If you see valid patterns in the file then the issue is probably caused by a circular import in django
Question:
I am getting this error "If you see valid patterns in the file then the issue is probably caused by a circular import in". I saw other stack flow questions and I know the error is coming from views.py but I cannot seem to figure out where the error is
views.py/myapp
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('<h1>Hey,Welcome</h1>')
urls.py/myapp
from django.urls import path
from myapp import views
urlpattern = [
path('',views.index, name='index')
]
urls.py/myproject
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('myapp.urls'))
]
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:Usersanaconda3libsite-packagesdjangourlsresolvers.py", line 698, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:Usersanaconda3libthreading.py", line 973, in _bootstrap_inner
self.run()
File "C:Usersanaconda3libthreading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:Usersanaconda3libsite-packagesdjangoutilsautoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:Usersanaconda3libsite-packagesdjangocoremanagementcommandsrunserver.py", line 134, in inner_run
self.check(display_num_errors=True)
File "C:Usersanaconda3libsite-packagesdjangocoremanagementbase.py", line 487, in check
all_issues = checks.run_checks(
File "C:Usersanaconda3libsite-packagesdjangocorechecksregistry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:Usersanaconda3libsite-packagesdjangocorechecksurls.py", line 14, in check_url_config
return check_resolver(resolver)
File "C:Usersanaconda3libsite-packagesdjangocorechecksurls.py", line 24, in check_resolver
return check_method()
File "C:Usersanaconda3libsite-packagesdjangourlsresolvers.py", line 481, in check
messages.extend(check_resolver(pattern))
File "C:Usersanaconda3libsite-packagesdjangocorechecksurls.py", line 24, in check_resolver
return check_method()
File "C:Usersanaconda3libsite-packagesdjangourlsresolvers.py", line 480, in check
for pattern in self.url_patterns:
File "C:Usersanaconda3libsite-packagesdjangoutilsfunctional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:Usersanaconda3libsite-packagesdjangourlsresolvers.py", line 706, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'myapp.urls' from 'E:\projects\django\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.
Answers:
Could you please just change urlpattern
to urlpatterns
in urls.py/myapp
and see if that solves your problem.
besides the answer changing this line help to disappear the error
in my app(sub app) ->urls.py
change below line
from . import views
with
from appname import views
Another possibility: You are using the reverse()
call on a field of a Class-based View and you need to use reverse_lazy()
instead.
I am getting this error "If you see valid patterns in the file then the issue is probably caused by a circular import in". I saw other stack flow questions and I know the error is coming from views.py but I cannot seem to figure out where the error is
views.py/myapp
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
return HttpResponse('<h1>Hey,Welcome</h1>')
urls.py/myapp
from django.urls import path
from myapp import views
urlpattern = [
path('',views.index, name='index')
]
urls.py/myproject
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('',include('myapp.urls'))
]
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:Usersanaconda3libsite-packagesdjangourlsresolvers.py", line 698, in url_patterns
iter(patterns)
TypeError: 'module' object is not iterable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:Usersanaconda3libthreading.py", line 973, in _bootstrap_inner
self.run()
File "C:Usersanaconda3libthreading.py", line 910, in run
self._target(*self._args, **self._kwargs)
File "C:Usersanaconda3libsite-packagesdjangoutilsautoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "C:Usersanaconda3libsite-packagesdjangocoremanagementcommandsrunserver.py", line 134, in inner_run
self.check(display_num_errors=True)
File "C:Usersanaconda3libsite-packagesdjangocoremanagementbase.py", line 487, in check
all_issues = checks.run_checks(
File "C:Usersanaconda3libsite-packagesdjangocorechecksregistry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:Usersanaconda3libsite-packagesdjangocorechecksurls.py", line 14, in check_url_config
return check_resolver(resolver)
File "C:Usersanaconda3libsite-packagesdjangocorechecksurls.py", line 24, in check_resolver
return check_method()
File "C:Usersanaconda3libsite-packagesdjangourlsresolvers.py", line 481, in check
messages.extend(check_resolver(pattern))
File "C:Usersanaconda3libsite-packagesdjangocorechecksurls.py", line 24, in check_resolver
return check_method()
File "C:Usersanaconda3libsite-packagesdjangourlsresolvers.py", line 480, in check
for pattern in self.url_patterns:
File "C:Usersanaconda3libsite-packagesdjangoutilsfunctional.py", line 49, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:Usersanaconda3libsite-packagesdjangourlsresolvers.py", line 706, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'myapp.urls' from 'E:\projects\django\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.
Could you please just change urlpattern
to urlpatterns
in urls.py/myapp
and see if that solves your problem.
besides the answer changing this line help to disappear the error
in my app(sub app) ->urls.py
change below line
from . import views
with
from appname import views
Another possibility: You are using the reverse()
call on a field of a Class-based View and you need to use reverse_lazy()
instead.