Django NoReverseMatch:找不到“testimonypost”的反向testimonypost'不是有效的视图函数或模式名称

Django NoReverseMatch:找不到“testimonypost”的反向testimonypost'不是有效的视图函数或模式名称,django,Django,我想不出来。我试过不同的方法,但都没有用。在my URL.py中对app_name进行注释可以让我完美地进入页面。关于应用程序名称,我应该知道什么吗? 有什么想法吗? views.py附在下面。感谢您的帮助。谢谢大家! #models.py class Testimony(models.Model): title = models.CharField(max_length=100) def get_absolute_url(self):

我想不出来。我试过不同的方法,但都没有用。在my URL.py中对app_name进行注释可以让我完美地进入页面。关于应用程序名称,我应该知道什么吗? 有什么想法吗? views.py附在下面。感谢您的帮助。谢谢大家!

 #models.py
    class Testimony(models.Model):
        title = models.CharField(max_length=100)

        def get_absolute_url(self):
           return reverse("Testimony:details", kwargs={"id": self.id} )

    #urls.py
    app_name='Testimony'
    urlpatterns=[
    path('testimonypost/', views.TestimonyOrderView, name='testimonypost'),]


    #template(traceback points to this line)
    <li><a href="{% url 'testimonypost'%}" class="glyphicon glyphicon-grain">&nbspTestimonies</a></li>

#views.py
def TestimonyOrderView(request):
    queryset_list=Testimony.objects.annotate().order_by('timestamp')

    paginator = Paginator(queryset_list, 20)
    page_request_var="page"
    page=request.GET.get(page_request_var)
    try:
        queryset=paginator.page(page)
    except PageNotAnInteger:
            queryset=paginator.page(1)
    except EmptyPage:
        queryset=paginator.page(paginator_num.pages)


    return render(request, 'testimony_post.html', {'queryset_list':queryset_list})

模板中的url部分错误。它必须是:{%url'证词:testimonypost%} 使用名称空间后,必须在URL中使用应用程序名称


请参见:

views.TestimonyOrderView.as_view我相信您指的是models.py中的类。我刚刚添加了views.py以便更清楚地说明。太好了!很高兴它起作用了。你能接受这个答案吗?