Home > database >  Is there a solution to "does not appear to have any patterns in it." problem?
Is there a solution to "does not appear to have any patterns in it." problem?

Time:12-12

While I was building my django project, I faced this error.

Error: The included URLconf '<module 'posts.urls' from "D:\Created apps\My project\posts\urls.py">' does not appear to have any patterns in it. If you see the 'urlpatterns' variable with valid patterns in the file then the issue is probably caused by a circular import.

So, here's given my project files. -------- posts/urls.py: ----------

from django.urls import path
from .views import BlogListView, BlogDetailView

url_patterns = [
    path('', BlogListView.as_view(), name='index'),
    path('post/<int:pk>/', BlogDetailView.as_view(), name='post_detail'),
]

----------- posts/views.py: -----------

from django.shortcuts import render
from django.views.generic import ListView, DetailView
from .models import Post

class BlogListView(ListView):
    model = Post
    template_name = 'index.html'

class BlogDetailView(DetailView):
    model = Post
    template_name = 'post_detail.html'

------------- config/urls.py: ----------

"""config URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.1/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 path, include

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

Could anyone help me to fix this problem, please?

CodePudding user response:

I can't comment yet, but in case your are still confused about what iklinac meant:
You have an extra underscore in your url_patterns variable in posts/urls.py.
It should be called urlpatterns.

  • Related