Django抛出NoReverseMatch错误

时间:2012-08-20 10:25:21

标签: python django

我是Django的新手。它抛出了这样一个错误:

File "/home1/monkevco/django/django_src/django/template/defaulttags.py", line 418, in render
raise e

NoReverseMatch: Reverse for '' with arguments '()' and keyword arguments '{}' not found.

我的urls.py看起来像:

urlpatterns = patterns('',
    url(r'^accounts/register/$',
        register,
        { 'backend': 'lbregistration.backends.simple.SimpleBackend' },
        name='registration_register'),
    url(r'^user/(?P<user_id>\d+)/$', profile, name='user_profile'),
    url(r'^accounts/avatar/', include('simpleavatar.urls')),
    url(r'^accounts/', include('registration.backends.default.urls')),
    url(r'^attachments/', include('attachments.urls')),
    url(r'^captcha/', include('captcha.urls')),

    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
    # to INSTALLED_APPS to enable admin documentation:
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),

    url(r'^', include('lbforum.urls')),
)

更新: Django版本 1.5

输入网址:http://monkev.com

错误位置:

<div id="brd-head" class="gen-content">
    <p id="brd-access"><a href="#brd-main">Skip to forum content</a></p>
    <p id="brd-title"><a href="{% url lbforum_index %}">{{ LBFORUM_TITLE }}</a></p>
    <p id="brd-desc">{{ LBFORUM_SUB_TITLE }}</p>
</div>

请帮我搞清楚。非常感谢你。

更新:

在调试页面中:

Request URL:    http://monkev.com/
Django Version: 1.5
Exception Type: NoReverseMatch
Exception Value:    
Reverse for '' with arguments '()' and keyword arguments '{}' not found.

...
...
 '/home1/monkevco/python/lib/python2.7/site-packages/Django-1.4.1-py2.7.egg',

我在python路径中调用Django 1.4.1,但为什么运行版本是Django 1.5?如何强制它到1.4.1?

1 个答案:

答案 0 :(得分:1)

你在运行Django主干吗?我建议运行最新版本Django 1.4.1。

Django 1.5中的{% url %}标记语法正在发生变化,这意味着必须更新使用它的所有模板,包括已安装应用程序中的模板。