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

Jah*_*nov 4 python django

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

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

例子:

<script src="{% static 'dashboard/js/dashboard.js?v=1.11.0' %}"></script>
Run Code Online (Sandbox Code Playgroud)

转换为

/static/dashboard/js/dashboard.js%3Fv%3D1.11.0 
Run Code Online (Sandbox Code Playgroud)

静态文件配置:

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',
) 
Run Code Online (Sandbox Code Playgroud)

可能是什么原因?

Udi*_*Udi 6

{% static path %}模板标签预计path是一个有效的文件路径和逃脱它。请改用以下语法:

 <script src="{% static 'dashboard/js/dashboard.js' %}?v=1.11.0"></script>
Run Code Online (Sandbox Code Playgroud)