python - 静态 django 2 的 TemplateSyntaxError

标签 python html django

我有这个代码:

HTML

{% load static %}
<!--[if lte IE 8]><script src="{% static game_reviews/css/ie/html5shiv.js %}"></script><![endif]-->

设置.py

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'game_reviews',]

STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',]

STATIC_URL = '/static/'

我的应用程序中有一个名为 static/game_reviews 的文件夹,里面有多个文件夹(js、css 等)。

我收到此错误:

/game_reviews/处的模板语法错误

无法解析其余部分:“game_reviews/css/ie/html5shiv.js”中的“/css/ie/html5shiv.js”

有什么帮助吗?提前致谢。

最佳答案

django static-files ,您应该发送路径作为参数:

{% load static %}
<!--[if lte IE 8]><script src="{% static "game_reviews/css/ie/html5shiv.js" %}"></script><![endif]-->
                                    <!-- ^^                                ^^-->

关于python - 静态 django 2 的 TemplateSyntaxError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50568495/

相关文章:

Python、MySQL 和一个奇怪的错误

python - 覆盖内置类 (Python)

html - 在透明图像上显示内容

html - 悬停时的 CSS 比例,叠加层和边框之间的空间

django - ModelForm 用户混合

python - 属性错误 : 'dict' object has no attribute 'predictors'

python - 在 Postgres 中更新 json 字段

Django,gunicorn 4 个 worker 的每秒请求量较低

javascript - 将元素放在另一个元素之上

Django: Model.objects.filter(a=X, b=Y) 没有返回想要的对象