pycharm:2019.3
Python:3.7
Django:3.0
--------------------------------------------------------------------------------------------
源代码:
1 # project中的url 2 from django.contrib import admin 3 from django.urls import path 4 from django.conf.urls import url, include 5 6 urlpatterns = [ 7 url(r'admin/', admin.site.urls), 8 url(r'^', include('myApp.urls', namespace="myApp")) 9 ]
1 # 应用中的url 2 from django.conf.urls import url 3 from . import views 4 urlpatterns = [ 5 url(r'^$', views.index, name="index"), 6 url(r'^attribles', views.attribles) 7 ]
报错提示为:
解决办法:
在[app_name]目录下的urls.py中的urlpatterns前面加上app_name='[app_name]', [app_name]代表你的应用的名称。
改正应用里url后的源代码:
1 from django.conf.urls import url 2 from . import views 3 4 app_name = 'myApp' 5 6 urlpatterns = [ 7 url(r'^$', views.index, name="index"), 8 url(r'^attribles', views.attribles) 9 ]
也可以修改project中的url,详情:https://blog.csdn.net/weixin_40841752/article/details/79335345?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task