我想在我加载的静态文件的URL中添加随机数(因为否则静态文件会被兑现而不会刷新)。但当我尝试加载页面时,会显示以下内容:
Exception Type: TemplateSyntaxError
Exception Value: Could not parse some characters: range|(1, 51)| | random
我的代码片段:
在包装器.html(内头标签)
<link rel="stylesheet"
href="{% static 'css/style.css' %}?v={{ range(1, 51) | random }}"
type="text/css"/>
在设置.py(这里可能出了点问题)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
我看了这个问题Generate random number with jinja2,并使用了答案中建议的同一行,但没有起作用。你知道吗
非常感谢
目前没有回答
相关问题 更多 >
编程相关推荐