Home > OS >  If you see valid patterns in the file then the issue is probably caused by a circular import in djan
If you see valid patterns in the file then the issue is probably caused by a circular import in djan

Time:03-24

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

Folder structure

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:\Users\anaconda3\lib\site-packages\django\urls\resolvers.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:\Users\anaconda3\lib\threading.py", line 973, in _bootstrap_inner
    self.run()
  File "C:\Users\anaconda3\lib\threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\anaconda3\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 134, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\anaconda3\lib\site-packages\django\core\management\base.py", line 487, in check
    all_issues = checks.run_checks(
  File "C:\Users\anaconda3\lib\site-packages\django\core\checks\registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\anaconda3\lib\site-packages\django\core\checks\urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\anaconda3\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
    return check_method()
  File "C:\Users\anaconda3\lib\site-packages\django\urls\resolvers.py", line 481, in check
    messages.extend(check_resolver(pattern))
  File "C:\Users\anaconda3\lib\site-packages\django\core\checks\urls.py", line 24, in check_resolver
    return check_method()
  File "C:\Users\anaconda3\lib\site-packages\django\urls\resolvers.py", line 480, in check
    for pattern in self.url_patterns:
  File "C:\Users\anaconda3\lib\site-packages\django\utils\functional.py", line 49, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\anaconda3\lib\site-packages\django\urls\resolvers.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.

CodePudding user response:

Could you please just change urlpattern to urlpatterns in urls.py/myapp and see if that solves your problem.

  • Related