Iwa*_*993 28 django templates filter built-in
我正在尝试使用此代码使用django内置的"默认"过滤器
{% load sekizai_tags static compress i18n %}
[...]
<title>{{ title|default:"nothing" }}</title>
Run Code Online (Sandbox Code Playgroud)
但它给了我以下例外
django.template.base.TemplateSyntaxError: default requires 2 arguments, 1 provided
Run Code Online (Sandbox Code Playgroud)
我在模板后端使用以下设置
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
str(APPS_DIR.path('templates')),
],
'OPTIONS': {
'debug': DEBUG,
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'allauth.account.context_processors.account',
'allauth.socialaccount.context_processors.socialaccount',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'sekizai.context_processors.sekizai',
],
},
},
]
Run Code Online (Sandbox Code Playgroud)
我的编辑器将代码标记为无效,但我检查了几千次 https://docs.djangoproject.com/en/1.8/ref/templates/builtins/
这是作为例子给出的:
{{ value|default:"nothing" }}
Run Code Online (Sandbox Code Playgroud)
我还尝试更改title var的名称,以确保它不是保留关键字.
Thi*_* J. 49
确保冒号后没有空格.
这是对的:
{{ title|default:"nothing" }}
Run Code Online (Sandbox Code Playgroud)
这引发了一个异常:
{{ title|default: "nothing" }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7650 次 |
| 最近记录: |