我不断收到此NoReverseMatch
错误。我的错误在于<form action>
标签。但是,如果我将格式更改为类似于<a href>
标签中的格式,那么一切都会好起来的。请指导我,因为我是 Django 新手。
<html>
<head><title>Feedbacks</title></head>
<body>
{% if store_list %}
<ul>
{% for store in store_list %}
<li><a href="/feedbacks/{{ store.store_name }}/add/">{{ store.store_name }}</a></li>
<form action="{% url 'view' store.store_name %}" method="post">
<input type="submit" value="Add" text="Add" />
</form>
{% endfor %}
</ul>
{% else %}
<p>List is empty.</p>
{% endif %}
</body>
</html>
我的网址.py
from django.conf.urls import patterns, url
from feedback import views
urlpatterns = patterns('',
#/feedbacks
url(r'^$', views.feedbacks, name="feedbacks"),
# /feedbacks/Kenny Rogers/add/
url(r'^(?P<store_name>.+)/add/$', views.add, name="add"),
url(r'^(?P<store_name>.+)/view/$', views.view, name="view"),
)
我的观点.py
from django.http import HttpResponse
from feedback.models import Store
from django.template import Context, loader
from django.shortcuts import render
def feedbacks(request):
store_list = Store.objects.all()
context = {"store_list" : store_list}
return render(request, "feedback/feedbacks.html", context)
def add(request, store_name):
return HttpResponse("I'm at the add page of %s. " % store_name)
def view(request, store_name):
return HttpResponse("I'm at the view page of %s. " % store_name)