Django-admin: TemplateDoesNotExist at /admin/plans/plan/

Posted

技术标签:

【中文标题】Django-admin: TemplateDoesNotExist at /admin/plans/plan/【英文标题】: 【发布时间】:2017-09-03 01:38:25 【问题描述】:

我正在尝试使 Django-plans 应用程序正常工作。除了/admin/plans/plan//admin/plans/order//admin/plans/userplan/ 等工作正常)之外,一切似乎都正常。

当我点击 Django-admin 中的计划时,它会返回:

TemplateDoesNotExist at /admin/plans/plan/ 

我不明白为什么它不存在。我查看了django-plans admin.py 文件,似乎Plan 没有指定任何特殊模板。

你知道有什么问题吗?

追溯

Environment: Request Method: GET Request URL: http://127.0.0.1:8000/admin/plans/plan/

Django Version: 1.10.5 Python Version: 2.7.10 Installed Applications: ['django.contrib.admin',  'django.contrib.auth',  'django.contrib.contenttypes',  'django.contrib.sessions',  'django.contrib.messages',  'django.contrib.staticfiles',  'django.contrib.sites',  'authapp',  'presentationapp',  'allauth',  'allauth.account',  'allauth.socialaccount',  'djmoney_rates',  'djmoney',  'api',  'productapp',  'django_extensions',  'mainapp',  'django_tables2',  'engineapp',  'dashboardapp',  'ticketapp',  'celery',  'dbbackup',  'bootstrap3',  'django_filters',  'widget_tweaks',  'cacheapp',  'adminapp',  'djcelery',  'import_export',  'plans',  'request',  'django.contrib.humanize'] Installed Middleware: ['django.middleware.security.SecurityMiddleware',  'django.contrib.sessions.middleware.SessionMiddleware',  'authapp.middleware.BasicAuthMiddleware',  'django.middleware.common.CommonMiddleware',  'django.middleware.csrf.CsrfViewMiddleware',  'django.contrib.auth.middleware.AuthenticationMiddleware',  'request.middleware.RequestMiddleware',  'django.contrib.messages.middleware.MessageMiddleware',  'django.middleware.clickjacking.XFrameOptionsMiddleware']

Template loader postmortem Django tried loading these templates, in this order:

Using engine django:
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\contrib\admin\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\contrib\auth\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\Desktop\Projekty\FS Dropbox\Dropbox\priceist\authapp\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\Desktop\Projekty\FS Dropbox\Dropbox\priceist\presentationapp\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\allauth\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\Desktop\Projekty\FS Dropbox\Dropbox\priceist\productapp\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django_extensions\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\Desktop\Projekty\FS Dropbox\Dropbox\priceist\mainapp\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django_tables2\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\Desktop\Projekty\FS Dropbox\Dropbox\priceist\engineapp\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\Desktop\Projekty\FS Dropbox\Dropbox\priceist\dashboardapp\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\bootstrap3\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\Desktop\Projekty\FS Dropbox\Dropbox\priceist\adminapp\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\djcelery\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\import_export\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\plans\templates\ordered_model\admin\order_controls.html (Source does not exist)
    * django.template.loaders.app_directories.Loader: C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\request\templates\ordered_model\admin\order_controls.html (Source does not exist)


Template error: In template C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\contrib\admin\templates\admin\change_list.html, error at line 82    ordered_model/admin/order_controls.html   72 :     % endif %    73 :       % endblock %    74 :     75 :       <form id="changelist-form" method="post"% if cl.formset.is_multipart % enctype="multipart/form-data"% endif % novalidate>% csrf_token %   76 :       % if cl.formset %    77 :         <div> cl.formset.management_form </div>    78 :       % endif %    79 :  80 :       % block result_list %    81 :           % if action_form and actions_on_top and cl.show_admin_actions %% admin_actions %% endif %    82 :            % result_list cl %     83 :           % if action_form and actions_on_bottom and cl.show_admin_actions %% admin_actions %% endif %    84 :       % endblock %    85 :       % block pagination %% pagination cl %% endblock %    86 :       </form>    87 :     </div>    88 :   </div>    89 : % endblock %    90 : 

Traceback:

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\core\handlers\exception.py" in inner
  39.             response = get_response(request)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\core\handlers\base.py" in _get_response
  217.                 response = self.process_exception_by_middleware(e, request)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\core\handlers\base.py" in _get_response
  215.                 response = response.render()

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\response.py" in render
  109.             self.content = self.rendered_content

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\response.py" in rendered_content
  86.         content = template.render(context, self._request)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\backends\django.py" in render
  68.             reraise(exc, self.backend)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\backends\django.py" in reraise
  89.     six.reraise(exc.__class__, new, sys.exc_info()[2])

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\backends\django.py" in render
  66.             return self.template.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render
  208.                     return self._render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\loader_tags.py" in render
  174.         return compiled_parent._render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\loader_tags.py" in render
  174.         return compiled_parent._render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in _render
  199.         return self.nodelist.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\loader_tags.py" in render
  70.                 result = block.nodelist.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\loader_tags.py" in render
  70.                 result = block.nodelist.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render
  994.                 bit = node.render_annotated(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\base.py" in render_annotated
  961.             return self.render(context)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\library.py" in render
  225.         _dict = self.func(*resolved_args, **resolved_kwargs)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py" in result_list
  339.             'results': list(results(cl))

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py" in results
  315.             yield ResultList(None, items_for_result(cl, res, None))

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py" in __init__
  306.         super(ResultList, self).__init__(*items)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\contrib\admin\templatetags\admin_list.py" in items_for_result
  217.             f, attr, value = lookup_field(field_name, result, cl.model_admin)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\contrib\admin\utils.py" in lookup_field
  286.             value = attr(obj)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\ordered_model\admin.py" in move_up_down_links
  69.             'query_string': self.request_query_string

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\loader.py" in render_to_string
  67.         template = get_template(template_name, using=using)

File "C:\Users\Milano\PycharmProjects\DropboxWorkspaces\priceist_workspace\priceist_venv\lib\site-packages\django\template\loader.py" in get_template
  25.     raise TemplateDoesNotExist(template_name, chain=chain)

Exception Type: TemplateDoesNotExist at /admin/plans/plan/ Exception Value: ordered_model/admin/order_controls.html

我无法进入计划,其他页面正常工作。

【问题讨论】:

一个 hacky 解决方案是创建一个名为“admin”的空白应用程序,并将其添加到 INSTALLED_APPS(在最底部)。管理应用程序将有模板文件夹和模板文件夹内的另一个名为“admin”的文件夹。然后你可以在'admin'文件夹中拥有'plans'文件夹。作为替代方案,您还可以将“管理员”文件夹添加到您已有的应用程序中。 @user2707389 我想知道是什么问题,为什么django找不到这样的模板。你知道吗?谢谢 我将解释 django 查找模板的方式:在您的情况下,它会遍历 INSTALLED_APPS 中包含的每个应用程序内的所有“模板”文件夹,并在其中查找“管理员”文件夹“计划”文件夹存在。在您的情况下,任何地方都没有“管理员”文件夹,它正在引发错误。只需在任何应用程序内的任何模板文件夹中创建一个管理文件夹,它就可以工作。或者把你的代码放到 github 上告诉我。 我试图在我的一个应用程序中添加管理文件夹,但没有帮助。如果它有帮助,我会感到惊讶,因为我可以访问其他型号的 Plan 应用程序。我在问题底部添加了屏幕截图。 我在下面发布了这个问题的正确答案。创建一个虚拟文件夹不是解决方案。 【参考方案1】:

对于遇到此确切错误的其他人,问题是您正在使用django-ordered-model 包,但您尚未在settings.py 中将ordered_model 添加到您的INSTALLED_APPS

【讨论】:

以上是关于Django-admin: TemplateDoesNotExist at /admin/plans/plan/的主要内容,如果未能解决你的问题,请参考以下文章

autoslugfield 进入 django-admin 界面?

找不到命令:django-admin.py

django-admin:command not found的解决办法

django-admin.py 不是内部或外部命令

在 Windows 7 上将“django-admin.py”路径添加到命令行

,我就弄懂了 Python Django 的 django-admin 命令行工具集