Django找不到密钥[keyname]

时间:2016-01-08 10:11:11

标签: django

我正在尝试将Django_bb添加为现有django项目中的应用程序,当我点击论坛中的很多链接时,我收到此错误...

Failed lookup for key [forum_settings] in u"[{'False': False, 'None': None, 'True': True}, {}, {}, {u'moderator': True, u'topics': [<Topic: askjdlaskjdlsakdj>], u'posts': 0, u'categories': [<Category: Languages>, <Category: Other>], u'forum': <Forum: English>}]"

这就是说forum_settings模块没有导入?导入语句在视图中没有问题,因此我不确定丢失的内容或在哪里,我不知道如何跟踪它,任何人都有任何想法?

编辑(添加完整的追溯):

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/forum/1/

Django Version: 1.8.4
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'main',
 'quiz',
 'study',
 'blog',
 'djangobb_forum',
 'pagination')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Template error:
In template /home/jeff/Django/langalang/langalang/djangobb_forum/templates/djangobb_forum/forum.html, error at line 8
   (Could not get exception message)

   1 : {% extends 'djangobb_forum/base.html' %}



   2 : {% load forum_extras %}



   3 : {% load pagination_tags %}



   4 : {% load i18n %}



   5 : 



   6 : {% block title %}{{ forum.name }} / {% endblock %}



   7 : {% block content %}



   8 :  {% autopaginate topics forum_settings.FORUM_PAGE_SIZE %} 



   9 : <div class="linkst">



   10 :     <div class="inbox">



   11 :         <div class="pagelink conl">{% paginate %}</div>



   12 :         {% if user.is_authenticated %}



   13 :             <p class="postlink conr"><a href="{% url 'djangobb:add_topic' forum.id %}">{% trans "New topic" %}</a></p>



   14 :         {% endif %}



   15 :         <ul><li><a href="{% url 'djangobb:index' %}">{% trans "Root" %}</a> </li><li>&raquo; {{ forum.name }}</li></ul>



   16 :         <div class="clearer"></div>



   17 :     </div>



   18 : </div>


Traceback:
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/jeff/Django/langalang/langalang/djangobb_forum/views.py" in show_forum

File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/shortcuts.py" in render
  67.             template_name, context, request=request, using=using)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
  99.         return template.render(context, request)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/backends/django.py" in render
  74.         return self.template.render(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/base.py" in render
  209.                     return self._render(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/base.py" in _render
  201.         return self.nodelist.render(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  135.         return compiled_parent._render(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/base.py" in _render
  201.         return self.nodelist.render(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
  65.                 result = block.nodelist.render(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/base.py" in render
  903.                 bit = self.render_node(node, context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
  79.             return node.render(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/pagination/templatetags/pagination_tags.py" in render
  90.             paginate_by = self.paginate_by.resolve(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/base.py" in resolve
  787.             value = self._resolve_lookup(context)
File "/home/jeff/Django/langalang/pyenv/local/lib/python2.7/site-packages/django/template/base.py" in _resolve_lookup
  839.                                                        (bit, current))  # missing attribute

Exception Type: VariableDoesNotExist at /forum/1/
Exception Value: Failed lookup for key [forum_settings] in u"[{'False': False, 'None': None, 'True': True}, {}, {}, {u'moderator': True, u'topics': [<Topic: askjdlaskjdlsakdj>], u'posts': 0, u'categories': [<Category: Languages>, <Category: Other>], u'forum': <Forum: English>}]"

1 个答案:

答案 0 :(得分:0)

由于未将上下文处理器添加到主django设置文件中,因此未传递上下文。我通过添加...来修复它。

TEMPLATE_CONTEXT_PROCESSORS = (
    ...
    'djangobb_forum.context_processors.forum_settings',