django 有没有解决“看起来没有任何模式”问题的方法?[已关闭]

rryofs0p  于 2022-12-14  发布在  Go
关注(0)|答案(1)|浏览(160)

Closed. This question is not reproducible or was caused by typos . It is not currently accepting answers.

This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed yesterday.
Improve this question
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?

sqougxex

sqougxex1#

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 .

相关问题