python - Django 1.10 将问号转换为静态文件 url 中的百分号

标签 python django

我正在将项目中的 Django 从 1.7 升级到 1.10。

所有静态文件都正确加载。但是,带有版本(或任何其他参数)的版本不是。原因是 Django 出于某种原因将问号转换为 %

例子:

<script src="{% static 'dashboard/js/dashboard.js?v=1.11.0' %}"></script>

转换为

/static/dashboard/js/dashboard.js%3Fv%3D1.11.0 

静态文件配置:

STATIC_URL = '/static/'
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
DEFAULT_FILE_STORAGE = 'django.core.files.storage.FileSystemStorage'
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
) 

可能是什么原因?

最佳答案

{% static path %} 模板标签期望 path 是一个有效的文件路径并将其转义。请改用以下语法:

 <script src="{% static 'dashboard/js/dashboard.js' %}?v=1.11.0"></script>

关于python - Django 1.10 将问号转换为静态文件 url 中的百分号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42530545/

相关文章:

python - groupby 并计算平均值但保留所有列

用于更新嵌入式设备的 Python 应用程序 - 可行吗?

django - 如何在Django登录表单中自定义变量 "next"?

mysql - 间歇性无法连接到 AWS RDS 上的 mysql(错误 2003)

python - 获取 Django 查询集中给定条目之前和之后的条目

javascript - 提交后如何隐藏表单?

javascript - 兼容 Django/React App : How to have both Django URLS (for the api to send data) and React URLS (to render my components) in my web app,

Python:调用函数真的很慢?

python - Pinguin rcorr 热图

python - 自定义 sharex 刻度标签