修复此“找不到页面(404)”错误

时间:2017-10-15 23:54:52

标签: python django url

我正在尝试访问我的应用程序中的页面,但我一直收到此错误:

  

找不到页面(404)请求方法:GET请求   网址:http://127.0.0.1:8000/nesting/Identity-nest/%7B%25%20url%20'嵌套:Symptoms_nest_list'%7D

     

使用Identity.urls中定义的URLconf,Django尝试了这些URL   模式,按此顺序:

^admin/ ^Identity/  
^nesting/ ^$[name='nesting']   
^nesting/ ^Identity-nest/$[name='Identity_nest_list']   
^nesting/ ^Symptoms-document/$[name='Symptoms_nest_list']  
^$ [name='login_redirect']
  

当前网址,嵌套/ Identity-nest / {%url   'nesting:Symptoms_nest_list'},与其中任何一个都不匹配。

这是我的主要urls.py

from django.conf.urls import url, include
from django.contrib import admin
from Identity import views


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^Identity/', include('Identities.urls', namespace = 'Identities')),
    url(r'^nesting/', include('nesting.urls', namespace = 'nesting')),
    url(r'^$', views.login_redirect, name = 'login_redirect'),
]

这是我的嵌套urls.py

from django.conf.urls import url
from nesting.views import Identity_view, Identity_nest_list_view, Symptoms_document_view
from . import views

urlpatterns = [
                    url(r'^$', Identity_view.as_view(), name = 'nesting'),
                    url(r'^Identity-nest/$', Identity_nest_list_view.as_view(), name = 'Identity_nest_list'),
                    url(r'^Symptoms-document/$', Symptoms_document_view.as_view(), name = 'Symptoms_nest_list')
]

这是我的views.py

class Symptoms_document_view(TemplateView):

    model = Symptoms
    template_name = 'nesting/Symptoms_list.html'

    def get(self, request):

        form = Symptom_Form()


        Symptoms_desc = Symptoms.objects.all()
        var = {'form':form, 'Symptoms_desc':Symptoms_desc}
        return render(request, self.template_name, var)



    def post(self, request):

        form = Symptom_Form(request.POST or None)

        Symptom_content = None

        if form.is_valid():

            Symptoms_description = form.save(commit = False)
            Symptoms_description.user = request.user
            Symptoms_description.save()

            Symptoms_content = form.cleaned_data['Symptoms_description']

            form = Symptom_Form()


            redirect('nesting:nesting')

        var = {'form': form, 'Symptoms_content': Symptoms_content}

        return render(request, self.template_name, var)

这是HTML模板中的一行,即Symptoms_document_view视图

的链接
<li class = "list-group-item"><a class = "nav-link" href="{%url 'nesting:Symptoms_nest_list'%}">{{Identity.First_Name}}  {{Identity.Last_Name}} </a> <p>NIS:  {{ Identity.NIS }}</p></li>

1 个答案:

答案 0 :(得分:0)

模板中的url标记周围需要空格:

 href="{% url 'nesting:Symptoms_nest_list' %}">

Django的模板解析器非常基本,并且不会识别没有空格的标签。