NoReverseMatch django 1.4 管理员

Posted

技术标签:

【中文标题】NoReverseMatch django 1.4 管理员【英文标题】:NoReverseMatch django 1.4 admin 【发布时间】:2012-06-10 21:17:33 【问题描述】:

我将一个项目从 1.1 迁移到 1.2,然后迁移到 1.3,所有这些都完美无缺。但是,当我将版本升级到 1.4 时,我不断收到一个

NoReverseMatch at /admin/<app_name>/<model_name>/
Reverse for 'app_list' with arguments '()' and keyword arguments ''app_label': ''' not found.

所有其他管理功能似乎都可以正常工作,但每次我尝试查看列表时,都会收到此 NoReverseMatch 错误。

我的管理员网址是:

(r'^admin/', include(admin.site.urls)),

这是我的回溯:

Template error:
In template /home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/contrib/admin/templates/admin/change_list.html, error at line 44
   Reverse for 'app_list' with arguments '()' and keyword arguments ''app_label': ''' not found.
   34 : </script>


   35 : % endif %% endif %


   36 : % endblock %


   37 : 


   38 : % block bodyclass %change-list% endblock %


   39 : 


   40 : % if not is_popup %


   41 : % block breadcrumbs %


   42 : <div class="breadcrumbs">


   43 : <a href="% url 'admin:index' %">% trans 'Home' %</a>


   44 : &rsaquo; <a href=" % url 'admin:app_list' app_label=cl.opts.app_label % "> app_label|capfirst|escape </a>


   45 : &rsaquo;  cl.opts.verbose_name_plural|capfirst 


   46 : </div>


   47 : % endblock %


   48 : % endif %


   49 : 


   50 : % block coltype %flex% endblock %


   51 : 


   52 : % block content %


   53 :   <div id="content-main">


   54 :     % block object-tools %


Traceback:
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
  136.                     response = response.render()
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/response.py" in render
  104.             self._set_content(self.rendered_content)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/response.py" in rendered_content
  81.         content = template.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/base.py" in render
  140.             return self._render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/loader_tags.py" in render
  123.         return compiled_parent._render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/loader_tags.py" in render
  123.         return compiled_parent._render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/base.py" in _render
  134.         return self.nodelist.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/defaulttags.py" in render
  281.                 return nodelist.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/loader_tags.py" in render
  62.             result = block.nodelist.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/base.py" in render
  823.                 bit = self.render_node(node, context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/debug.py" in render_node
  74.             return node.render(context)
File "/home/ibustama/yalea/env-yalea/lib/python2.6/site-packages/django/template/defaulttags.py" in render
  424.                         raise e

Exception Type: NoReverseMatch at /admin/auth/user/
Exception Value: Reverse for 'app_list' with arguments '()' and keyword arguments ''app_label': ''' not found.

【问题讨论】:

您似乎忘记在您的INSTALLED_APPS 配置中包含一个应用程序。您是否按照these 的步骤使用管理页面? 您好,谢谢,我确实遵循了这些步骤。我想也许我错过了设置文件上的一些新的默认应用程序,甚至检查了顺序。问题依旧。无论如何,我发现了问题(而且很愚蠢),所以我会发布答案。 【参考方案1】:

我的错误最终相当愚蠢。我的一个自定义上下文处理器重新定义了“cl”上下文变量,因此使以下标记失败:

% url 'admin:app_list' app_label=cl.opts.app_label %

我只需要对我自己的上下文处理器和模板进行一些更改(并使用更好的上下文处理器变量名称)。

注意:我不知道为什么这之前没有让我感到困扰。理论上,即使在 1.1 中,它也应该是一个问题。

【讨论】:

以上是关于NoReverseMatch django 1.4 管理员的主要内容,如果未能解决你的问题,请参考以下文章

Django 查看错误 - NoReverseMatch

网址 django,NoReverseMatch

如何修复 Django“NoReverseMatch”错误

Django 测试 - NoReverseMatch

NoReverseMatch 与 Django 网址

为啥 Django 模板模式匹配错误的视图并导致 NoReverseMatch 错误?