简体   繁体   中英

The included URLconf does not appear to have any patterns in it. Error in Django

The included URLconf '<module 'myapp.urls' from 'C:\\Users\\Hp\\Desktop\\Python\\Django Projects\\myproject\\myapp\\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.

This is the error that I am getting while building my django app.

Here is urls.py from myapp -

from django.urls import path
from . import views

urlpatterns=[
    path('', views.index, name='index')
]

Here is views.py -

from django.shortcuts import render
from django import HttpResponse

# Create your views here.
def index(request):
    return HttpResponse('<h1>Hey, Welcome</h1>')

this is from urls.py from myproject-

"""myproject 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('myapp.urls')),
]

try to edit your view file like the following:

from django.shortcuts import render

#this is new 
from django.http import HttpResponse


# Create your views here.
def index(request):
    return HttpResponse('<h1>Hey, Welcome</h1>')

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