views:

172

answers:

1

I'm writing a basic Django application. For testing / development purposes I'm trying to serve the static content of the website using Django's development server as per http://docs.djangoproject.com/en/dev/howto/static-files/#howto-static-files.

My urls.py contains:

    (r'^admin/(.*)', admin.site.root),

    (r'^(?P<page_name>\S*)$', 'Blah.content.views.index'),

    (r'^static/(?P<path>.*)$', 'django.views.static.serve',
        {'document_root': 'C:/Users/My User/workspace/Blah/media',
         'show_indexes': True})

However, when I try to access a file such as http://localhost:8000/static/images/Logo.jpg Django gives me a 404 error claiming that "No Page matches the given query."

When I try to access a file such as http://localhost:8000/static/images/Blah%20Logo.jpg it serves the file!

What's going on?

+10  A: 

You have wrong patterns order in urls.py.

When you try to retrieve path without space it matches:

(r'^(?P<page_name>\S*)$', 'Blah.content.views.index'),

not static.serve and of course you have not such page, But when you try to access path with space it matches proper static.serve pattern because it is more generic and allows spaces.

To solve this problem just swap those patterns.

Alex Koshelev
Obviously! Thanks so much!
fluffels