重定向django上的NoReverseMatch

时间:2016-09-05 13:08:42

标签: python django

我有一个简单的表单,用户输入一些文本,在提交时执行操作并将结果返回给用户。 例如,用户输入一堆文本,并在提交时显示带有句子计数的页面。

views.py

from django.core.urlresolvers import reverse_lazy, reverse
from django.http import HttpResponseRedirect
from django.views.generic import ListView, CreateView, DetailView


class CreateEntry(CreateView):
    model = Entryt
    fields = ['text']


    def form_valid(self, form):
        return HttpResponseRedirect(reverse('app:result'))


class ResultView(DetailView):
    model = Entryt
    context_object_name = 'fl'
    template_name = 'flesch/result.html'

def get_queryset(self):         返回Entryt.objects.get(pk =' entryt_id')

项目网址包含此应用

url(r'^flesch/', include('flesch.urls', namespace='app')),

app urls.py

from django.conf.urls import url
from .views import ResultView, CreateEntry

urlpatterns = [

    url(r'^$', CreateEntry.as_view(), name='create'),
    url(r'^(?P<pk>[0-9]+)/$', ResultView.as_view(), name='result'),
]
提交表单时出现

错误消息

NoReverseMatch at /flesch/
Reverse for 'result' with arguments '()' and keyword arguments '{}'           

not found. 1 pattern(s) tried: ['flesch/(?P<pk>[0-9]+)/$']

我是如何做到这一点的正确途径或如何解决这个问题?

0 个答案:

没有答案