[Django]-Django.core.exceptions.ImproperlyConfigured. The included URLconf does not appear to have any patterns in it

4πŸ‘

βœ…

if you are using django 2.0.1 you should be aware that django has changed its urlpatterns from django 2.0
use the below code in your urls and remove that admin.autodiscover() as its not needed

from django.urls import path

urlpatterns = [
    path('articles/2003/', views.special_case_2003),
    path('articles/<yyyy:year>/', views.year_archive),
    ...
]

change this line

path(r'^models/(?P<pk>[0-9]+)$', views.model_detail),

to

path('models/<int:pk>/', views.model_detail),

and

path(r'^models/$', views.model_list),

to

path('models/', views.model_list),

As for Django 4.2.1:
if you use the @login_required decorator on a view and you provide the β€˜login_url’ argument ensure that its value is either a
plain url or view name.
i.e.
from django.contrib.auth.decorators import login_required

avoid this: as it will throw an the above mentioned error

@login_required(login_url=reverse("login"))
def home(request):
    return render(request, "auth_test/home.html")

rather use;

@login_required(login_url="login")
def home(request):
    return render(request, "auth_test/home.html")

Django will automatically determine if what was provided is a url
or a view name and it will handle the necessary resolving

Here is a screen shot of the error in the vscode terminal

The above mentioned error is reproducible if that is done

πŸ‘€Exprator

0πŸ‘

The issue is in crud_operations/urls.py because you are using include to try and link the view to the url. include is for linking a url to another url.py set of configurations. To link a view function to the url, simply type the name of the function there as such:

from crud_operations import views

urlpatterns = [
     url(r'^models/$', views.model_list),
     url(r'^models/(?P<pk>[0-9]+)$', views.model_detail),
]

Good luck!

πŸ‘€Rohan Varma

Leave a comment