views:

226

answers:

1

I'm using django and realized that when the filename that the user wants to access (let's say a photo) has the pound sign, the entry in the url.py does not match.

Any ideas?

    url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root':
    MEDIA_ROOT},

it just says:

"/home/user/project/static/upload/images/hello" does not exist

when actually the name of the file is:

hello#world.jpg

Thanks, Nico

+6  A: 

This isn't really Django's fault - the pound (#) sign in a URL means to load the specified anchor on the page. You need to encode the pound sign in your URL to get the browser to request the full image path:

/home/user/project/static/upload/images/hello%23world.jpg

In a Django template you can use the urlencode template tag.

Lance McNearney
Just to add: the browser won't send anything to the server from the pound (#) sign onwards, this is why you need to encode it.
Mario Menger