反向'写'参数'()'和关键字参数' {}'未找到。尝试过0种模式:[]

时间:2016-01-31 10:22:04

标签: python django href django-urls

我正在从django 1.7更新到django 1.9,我收到此错误消息。

" NoReverseMatch在/ gaestebuch /" "反向'写'参数'()'和关键字参数' {}'未找到。尝试了0种模式:[]"

这是我的代码:

urls.py:

from django.conf.urls import url
from . import views

app_name = 'gaestebuch'

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^(?P<id>[0-9]+)/$', views.result, name='result'),
    url(r'^comment/$', views.comment, name='comment'),
    url(r'^write/', 'gaestebuch.views.write', name='write'),
    url(r'^register/$', views.register, name='register'),
    url(r'^login/$', views.user_login, name='login'),
    url(r'^logout/$', views.user_logout, name='logout'),
    url(r'^(?P<pk>[0-9]+)/delete$', views.delete_eintrag,       
name='delete_eintrag'),  
    url(r'^(?P<pk>[0-9]+)/comment/$', views.write_comment_eintrag,    
name='write_comment_eintrag'),
]

的index.html

<div id = "content_main">
    <div id = "header_main">
        <div id = "logo_main">
            {% if user.is_authenticated %}
            <p>Hallo {{ user.username }}! :))</p>
            {% else %}
            <p>Hallo ihr Lieben!</p>
            {% endif %}

        </div>
        <div id= "write_main">
            {% if user.is_authenticated %}
            <p><a href="/gaestebuch/logout/">Logout</a></p>
            <p><a href="{% url 'gaestebuch: write' %}">Eintrag Verfassen</a></p>
            {% else %}
            <p><a href="{% url 'register' %}">Hier Registrieren</a></p>
            <p><a href="{% url 'login' %}">Hier Einloggen</a></p><br />
            {% endif %}
        </div>
    </div>
    <div id = "list_main">
        {% if latest_eintrage_list %}
            <ul>
    <br>
            {% for e in latest_eintrage_list %}
         <li>
        <div id="comment_main">
        {{ e.author }}
        <br>
        </div>
        <a href="{% url 'gaestebuch:result' e.id %}">{{ e.title }}</a>
        <br>
        <div id="comment_main">
        Kommentare: {{ e.comments.count }} | {{ e.created_date }} | {{ e.get_typ_display }}
        </div>
        <hr>
        </li>
            {% endfor %}
            <br>
    </ul>
        {% else %}
            <p>Keine Eintraege verfuegbar!</p>
        {% endif %}     </div>
    <div id = "footer_main">
        <a href="">Impressum</a>
    </div>
</div>

这是指这一行:

<p><a href="{% url 'gaestebuch: write' %}">Eintrag Verfassen</a></p>

此:

<p><a href="{% url 'write' %}">Eintrag Verfassen</a></p>

也不起作用。

有人可以告诉我这是什么问题吗?

1 个答案:

答案 0 :(得分:0)

删除gaestebuch和write之间的空格:

<p><a href="{% url 'gaestebuch:write' %}">Eintrag Verfassen</a></p>