django2.0 報錯 does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.


 

raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: 
The included URLconf
'<module 'users.urls' from 'D:\\mygitfile\\meiduo_project\\meiduo_mall\\meiduo_mall\\apps\\users\\urls.py'>' does not appear to have any patterns in it.
If you see valid patterns in the file then the issue is probably caused by a circular import.

 

錯誤來源:配置子應用的url時,啟動django項目報錯

錯誤原因:啟動django項目,django框架會加載路由配置,如果在總路由添加了子應用,

那么需要在子應用文件下新建一個urls.py文件 並且要加上 urlpatterns=[]

例如:主應用 url.py

"""meiduo_mall URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('admin/', admin.site.urls),
    path('users/', include(('users.urls', 'users'), namespace='users')),
]

子應用urls.py

from django.urls import path
from . import views

urlpatterns=[
    path('register/',views.RegisterView.as_view(),name='register')
]

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM