解决Django:NoReverseMatch: Reverse for 'xxx' not found . 'xxx' is not a valid view function or pattern

最近学写templates对以前写的代码进行了优化,优化后发现项目起不来了,报如下错误:

web端如下

解决Django:NoReverseMatch: Reverse for 'xxx' not found . 'xxx' is not a valid view function or pattern_第1张图片

 

pycharm端如下

File "E:\Anaconda3\lib\site-packages\django\urls\resolvers.py", line 622, in _reverse_with_prefix
    raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'index' not found. 'index' is not a valid view function or pattern name.
[12/Mar/2019 16:43:52] "GET /pagenum/ HTTP/1.1" 500 109607

知道是urls.py里的地址写的有问题,检查了发现,是app里的urls.py里新加了app_name=‘xxx’的参数

from django.urls import path
from . import views
app_name='test1_app'

urlpatterns = [
    path('', views.index, name='index'),
    path('pagenum/', views.pagedetail, name='pagedetail'),
]

自己在templates里html文件模板用{% url ‘xxx’%}解析时没有跟app_name,具体如下:




    
    pagedetail


    

据此找到问题,更改HTML文件中url标签部分;

test1_app:index' %}"> home 

问题解决!希望对各位躲过自己挖的坑,有所帮助!

你可能感兴趣的:(Python,web)