Circular import in Django
Im getting this error : 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 whenever i try python manage.py runserver
app urls.py
from django.urls import path
from . import views
urlpatterns = [
path ('', views.index, name='index'),
]
project urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.urls')),
]
app Views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('<h1> Hello man</h1>')
Im using Django 4.1, and Python 3.10.10, I also tried this with python 3.12 and Django 5.1.4, still error persisted.
Without this particular line of code below in the parent app, the program runs fine.
path('', include('myapp.urls')),
but when I include the above line of code I get the following error: "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."
I tried changing python environments, directories, rewriting the code and trying out in different python and django versions but the error still persisted.
Tried changing 'from . import views' to 'from myapp import views'. Didn't work. I checked other questions regarding this and it didn't fix the problem.