简体   繁体   中英

django.core.exceptions.ImproperlyConfigured: The included URLconf 'notes.urls' does not appear to have any patterns in it

I get this error in the root directory, not in an app. The code in urls.py of this root directory is:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('write_notes.urls'))    # `write_notes` is the name of my app.
]

Code in write_notes.urls:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.IndexView.as_view(), name='index-page'),
    path('/signup', views.SignupView.as_view(), name='signup-page'),
    path('/note', views.WriteNoteView.as_view(), name='write-note-page')
]

What is the error and how do I fix it?

Maybe you are missing the following code to add in notes.urls

from django.urls.resolvers import URLPattern //*

urlpatterns = [

]

This error happened to me too, and the reason for it was the use of reverse in one of my classes, which was used in urlpatterns. Therefore, if you have used reverse in one of the SignupView and WriteNoteView classes, it is most likely the reason for the error. I solved the problem by converting reverse("pathname ") to absolute path as bellow:

login_url = reverse('login')

changed to:

login_url ='accounts/login'

Although reverse('pathname') is highly recommonded and result of two above code is same, but i don't know why this solve the error. I hope this help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM