我正在尝试在Django中的管理模板的submit_line.html
的{{1}}中删除,但出现此错误:
DetailView
我的InvalidTemplateLibrary at /
Module data_operations.templatetags.data_operations_tags does not have a variable named 'register'
包含我的应用名称:
settings.py
和模板数据:
INSTALLED_APPS = [
...
'data_operations',
...
]
这里是TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# os.path.join(PROJ_DIR, 'templates')
],
'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',
'data_operations.apptemplates.load_setting'
],
'libraries':{
'data_operations_tags': 'data_operations.templatetags.data_operations_tags',
}
},
},
]
:
data_operations/templatetags/data_operations_tags.py
我确保在from django.contrib.admin.templatetags.admin_modify import submit_row
from django.template.loader import get_template
from django import template
t = get_template('admin/data_operations/submit_line.html')
register = template.Library()
register.inclusion_tag(t, takes_context=True)(submit_row)
目录中也包含一个空的__init__.py
。
最后,我有两个模板。
templatetags
:
data_operations/templates/admin/data_operations/change_form.html
还有{% extends "admin/change_form.html" %}
{% load data_operations_tags %}
{% block submit_buttons_bottom %}{% submit_row %}{% endblock %}
(除了我在代码中添加了一个自定义的“取消”按钮外,它与默认设置完全相同):
data_operations/templates/admin/data_operations/submit_line.html
我不明白为什么错误说明{% load i18n admin_urls %}
<div class="submit-row">
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save" />{% endif %}
{% if show_delete_link %}
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
<p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink">{% trans "Delete" %}</a></p>
{% endif %}
<input type=button value="Cancel" onClick="javascript:history.go(-1);">
{% if show_save_as_new %}<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew" />{% endif %}
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother" />{% endif %}
{% if show_save_and_continue %}<input type="submit" value="{% trans 'Save and continue editing' %}" name="_continue" />{% endif %}
</div>
没有名为data_operations_tags
的变量。该变量显然在代码中。请帮忙!