我是Django的新手,我遇到了NoReverseMatch错误.有谁知道我怎么解决这个问题?
异常值:反向’profile_list.html’,参数'()’和关键字参数'{}’未找到.
edit_profile.html
<h1>Add Profile</h1>
<form action="{% url 'questions-new' %}" method="POST">
{% csrf_token %}
<ul>
{{ form.as_ul }}
</ul>
<input type="submit" value="Save" />
</form>
<a href="{% url 'profile-list' %}">back to list</a>
urls.py
from django.conf.urls import patterns, include, url
import questions.views
urlpatterns = patterns('',
url(r'^$', questions.views.ListProfileView.as_view(),
name='profile-list'),
url(r'^new$', questions.views.CreateProfileView.as_view(),
name='questions-new',),
)
views.py
from django.views.generic import ListView
from questions.models import Profile
from django.core.urlresolvers import reverse
from django.views.generic import CreateView
class ListProfileView(ListView):
model = Profile
template_name = 'profile_list.html'
class CreateProfileView(CreateView):
model = Profile
template_name = 'edit_profile.html'
def get_success_url(self):
return reverse('profile_list.html')
最佳答案 你的get_success_url错了.将其更改为以下内容:
def get_success_url(self):
return reverse('profile-list')
reverse应与您在urls.py模式中提供的名称一起使用,而不是模板名称.