Python Django-urls.py-带哈希/磅(#)符号的文件名?
我正在使用django,并意识到当用户想要访问的文件名(比如照片)带有磅号时,url.py中的条目不匹配 有什么想法吗Python Django-urls.py-带哈希/磅(#)符号的文件名?,python,regex,django,Python,Regex,Django,我正在使用django,并意识到当用户想要访问的文件名(比如照片)带有磅号时,url.py中的条目不匹配 有什么想法吗 url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': MEDIA_ROOT}, 当文件的实际名称为: hello#world.jpg 谢谢, Nico这其实不是Django的错-URL中的磅(#)符号意味着在页面上加载指定的锚。您需要在URL中对磅
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root':
MEDIA_ROOT},
当文件的实际名称为:
hello#world.jpg
谢谢,
Nico这其实不是Django的错-URL中的磅(#)符号意味着在页面上加载指定的锚。您需要在URL中对磅符号进行编码,以使浏览器请求完整图像路径:
/home/user/project/static/upload/images/hello%23world.jpg
在Django模板中,您可以使用模板标记。只是为了添加:从英镑(#)符号开始,浏览器不会向服务器发送任何内容,这就是您需要对其进行编码的原因。
/home/user/project/static/upload/images/hello%23world.jpg