Home > Back-end >  PYTHON 3.6.0 & DJANGO 3.5.0 'module' object is not iterable when running django website to
PYTHON 3.6.0 & DJANGO 3.5.0 'module' object is not iterable when running django website to

Time:02-10

So i'm gonna run my Django project with python manage.py runserver but suddenly there comes an error like these:

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "D:\ITHB MIT\TUGAS AKHIR\PRACTICE\program\Django Application\venv\lib\site-packages\django\urls\resolvers.py", line 590, in url_patterns
    iter(patterns)
TypeError: 'module' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Users\USER\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "D:\ITHB MIT\TUGAS AKHIR\PRACTICE\program\Django Application\venv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "D:\ITHB MIT\TUGAS AKHIR\PRACTICE\program\Django Application\venv\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
    self.check(display_num_errors=True)
  File "D:\ITHB MIT\TUGAS AKHIR\PRACTICE\program\Django Application\venv\lib\site-packages\django\core\management\base.py", line 395, in check
    include_deployment_checks=include_deployment_checks,
  File "D:\ITHB MIT\TUGAS AKHIR\PRACTICE\program\Django Application\venv\lib\site-packages\django\core\management\base.py", line 382, in _run_checks
    return checks.run_checks(**kwargs)
  File "D:\ITHB MIT\TUGAS AKHIR\PRACTICE\program\Django Application\venv\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
    new_errors = check(app_configs=app_configs)
  File "D:\ITHB MIT\TUGAS AKHIR\PRACTICE\program\Django Application\venv\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "D:\ITHB MIT\TUGAS AKHIR\PRACTICE\program\Django Application\venv\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "D:\ITHB MIT\TUGAS AKHIR\PRACTICE\program\Django Application\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\ITHB MIT\TUGAS AKHIR\PRACTICE\program\Django Application\venv\lib\site-packages\django\urls\resolvers.py", line 597, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'project_settings.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

And there is my project.settings.urls

"""project_settings URL Configuration
"""
from django.contrib import admin
from django.urls import path, include

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('', include('ml_app.urls')),
]   static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

And here are my ml_app.urls

        """project_settings URL Configuration """ 
from django.contrib import admin 
from django.urls import path, include 
from . import views 
from .views import about, index, predict_page,cuda_full
        
        app_name = 'ml_app' handler404 = views.handler404
        
        urlpatterns = [
            path('', index, name='home'),
            path('about/', about, name='about'),
            path('predict/', predict_page, name='predict'),
            path('cuda_full/',cuda_full,name='cuda_full'), 
    ]

Does someone know how to fix that error? It's pretty important for my final test =(

CodePudding user response:

You have some circular imports. It means you have probably used imports from A to B, and then from B to A. You have to check dependencies. Sometime if you use a funtion, that imports model, and later you imports same function to that model, it would import infinitely. Check it in your code. Btw. don't import views and then every View from that views in the same file. It might be confusing

from django.contrib import admin 
from django.urls import path, include 
from ml_app.views import about, index, predict_page,cuda_full, handler404

Check this article to read more about issue.

CodePudding user response:

I think your app urls.py should be somethings like this:

        """project_settings URL Configuration """ 
from django.contrib import admin 
from django.urls import path, include  
from your-app-name import views  
        
        app_name = 'ml_app' handler404 = views.handler404
        
        urlpatterns = [
            path('', views.index, name='home'),
            path('about/', views.about, name='about'),
            path('predict/', views.predict_page, name='predict'),
            path('cuda_full/',views.cuda_full,name='cuda_full'), 
    ]
  • Related