开发者

Django - urls.py - Filenames with a hash/pound (#) sign?

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_ro开发者_StackOverflow社区ot':
    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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜