Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django中未正确加载自定义模板_Django_Django Templates_Templatetags - Fatal编程技术网

Django中未正确加载自定义模板

Django中未正确加载自定义模板,django,django-templates,templatetags,Django,Django Templates,Templatetags,我试图在Django中对管理员模板的DetailView的submit\u line.html进行细分,但出现以下错误: InvalidTemplateLibrary at / Module data_operations.templatetags.data_operations_tags does not have a variable named 'register' Mysettings.py包含我的应用程序名称: INSTALLED_APPS = [ ... 'dat

我试图在Django中对管理员模板的
DetailView
submit\u line.html
进行细分,但出现以下错误:

InvalidTemplateLibrary at /
Module  data_operations.templatetags.data_operations_tags does not have a variable named 'register'
My
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\u operations/templatetags/data\u operations\u 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)
我确保在
templatetags
目录中也包含一个空的
\uuuu init\uuuu.py

最后,我有两个模板。
data\u operations/templates/admin/data\u operations/change\u form.html

{% extends "admin/change_form.html" %}
{% load data_operations_tags %}
{% block submit_buttons_bottom %}{% submit_row %}{% endblock %}
data\u operations/templates/admin/data\u operations/submit\u line.html
(与默认值完全相同,只是我在代码中添加了一个自定义的“取消”按钮):

{%load i18n admin\u url%}
{%if show_save%}{%endif%}
{%if show_delete_link%}
{%url选择| admin_urlname:'delete'original.pk | admin_urlquote作为delete_url%}

{%endif%} {%if显示\保存\为\新%}{%endif%} {%if显示\保存\和\添加\另一个%}{%endif%} {%if show_save_and_continue%}{%endif%}

我不明白为什么错误是说
data\u operations\u tags
没有名为
register
的变量。这个变量显然存在于代码中。请帮忙

如果我移动
register=template.Library()
使其出现在
t=get\u template('admin/data\u operations/submit\u line.html')
中的
data\u operations\u tags.py
中,我现在会得到一个名为apptemplates的模块的导入错误。啊!
{% 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>