在我安装了django-postman和django- TemplateNotFound之后,我得到了一个消息。我显然是分开安装的--先是django-postman,然后是django-messages。这很简单,但我花了几个小时试图解决这个问题。
我使用的是Django 1.8,这是一个使用pip的全新基础安装。然后我安装了上面的两个包。我的settings.py文件的模板部分如下:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
#os.path.join(BASE_DIR, 'templates/django_messages'),
],
'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',
],
},
},
]在我的INSTALLED_APPS元组中,我也安装了上述包。
下面是我添加到urls.py中的内容:
url(r'^messages/', include('django_messages.urls')),没有对系统进行任何其他更改,但当我转到/messages时,我收到以下错误消息:
TemplateDoesNotExist at /messages/inbox/
django_messages/inbox.html
Request Method: GET
Request URL: http://localhost:8000/messages/inbox/
Django Version: 1.8.3
Exception Type: TemplateDoesNotExist
Exception Value:
django_messages/inbox.html
Exception Location: /projects/.virtualenvs/blatter/lib/python2.7/site-packages/django/template/loader.py in render_to_string, line 138
Python Executable: /projects/.virtualenvs/blatter/bin/python
Python Version: 2.7.6发布于 2016-03-10 23:39:56
这个问题是因为它从站点的base.html扩展而来。在邮递员文档中也有提到:- https://django-postman.readthedocs.org/en/latest/quickstart.html#templates
The postman/base.html template extends a base.html site template, in which some blocks are expected:
title: in <html><head><title>, at least for a part of the entire title string
extrahead: in <html><head>, to put some <script> and <link> elements
content: in <html><body>, to put the page contents
postman_menu: in <html><body>, to put a navigation menu一个可能的解决方案可以在这里找到:- django-postman extends a base.html that does not exist
发布于 2015-07-17 02:46:44
在检查了一个调用的模板并更改了扩展/继承参数后,django-messages解决了这个问题。
被调用的文件inbox.html继承了"django_messages/base.html“...它工作得很好。"base.html“继承自"base.html”,所以这里似乎有一些循环逻辑导致了错误。这是默认的,不是我添加的。当我从"base.html“中删除扩展/继承声明,这样它就不会从自身继承时,django-messages就起作用了。
也许Django 1.8使用模板改变了一些逻辑?无论哪种方式,问题都解决了。
https://stackoverflow.com/questions/31458813
复制相似问题