gpt4 book ai didi

python - Django - urls.py - 带有井号/井号 (#) 符号的文件名?

转载 作者:太空宇宙 更新时间:2023-11-03 12:42:51 25 4
gpt4 key购买 nike

我正在使用 django 并意识到当用户想要访问的文件名(比方说照片)有井号时,url.py 中的条目不匹配。

有什么想法吗?

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

它只是说:

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

实际上文件名是:

hello#world.jpg

谢谢,妮可

最佳答案

这真的不是 Django 的错 - URL 中的井号 (#) 表示在页面上加载指定的 anchor 。您需要对 URL 中的井号进行编码,以使浏览器请求完整的图像路径:

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

在 Django 模板中,您可以使用 urlencode模板标签。

关于python - Django - urls.py - 带有井号/井号 (#) 符号的文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2573803/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com