我创建我的第一个Django应用程序使用本教程https://docs.djangoproject.com/en/dev/intro/tutorial04/。我到最后的任务,现在我有这个错误,我不知道如何解决。我要去向您展示我的整个计划,并且我会尽力指出我在哪里做错了投票。这个应用就像投票。它显示一个民意调查和一些选择,你必须投票。django错误NoReverseMatch,而我渲染
这是我的错误
TemplateSyntaxError at /polls/1/
Caught NoReverseMatch while rendering: u'myapp' is not a registered namespaceRequest Method: GET
Request URL: http://cat.pythonanywhere.com/polls/1/
Django Version: 1.3.5
Exception Type: TemplateSyntaxError
Exception Value: Caught NoReverseMatch while rendering: u'myapp' is not a registered namespace
Exception Location: /usr/local/lib/python2.7/site-packages/django/template/defaulttags.py in render, line 450
Python Executable: /usr/local/bin/uwsgi
Template error
In template /home/cat/mysite/myapp/templates/myapp/detail.html, error at line 5
Caught NoReverseMatch while rendering: u'myapp' is not a registered namespace
1 <h1>{{ poll.question }}</h1>
2
3 {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
4
5 <form action="{% url myapp:vote poll.id %}" method="post">
6 {% csrf_token %}
7 {% for choice in poll.choice_set.all %}
8 <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
9 <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
10 {% endfor %}
11 <input type="submit" value="Vote" />
12 </form>
我认为错误在我detail.html隐藏
<h1>{{ poll.question }}</h1>
{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
<form action="{% url myapp:vote poll.id %}" method="post">
{% csrf_token %}
{% for choice in poll.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
<label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
{% endfor %}
<input type="submit" value="Vote" />
</form>
我Urls.py
from django.conf.urls.defaults import *
from mysite.myapp import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^(?P<poll_id>\d+)/$', views.detail, name='detail'),
url(r'^(?P<poll_id>\d+)/results/$', views.results, name='results'),
url(r'^(?P<poll_id>\d+)/vote/$', views.vote, name='vote'),
)
我希望有人能帮助我因为我不知道如何解决这个错误
您不应该在/en/1.3/intro/tutorial04/而不是/ en/dev/intro/tutorial04 /中使用教程吗? – Nick 2013-02-14 04:36:11
@nick你可能是对的。 – supersheep1 2013-02-14 04:53:02
当您遇到命名空间错误时,问题出在您的主要网址 – catherine 2013-02-14 04:56:11