TypeError: объект 'module' не является итерируемым в django 4

TypeError: 'module' object is not iterable in django 4

Я получаю приведенную выше ошибку, она сохраняется достаточно долго, и на данный момент мне действительно нужна помощь. Я использую pickle для загрузки ML модели, Django для получения пользовательского ввода. Ниже приведена ошибка, мой файл urls.py и файл views.py.

Любая помощь будет высоко оценена.

Весь код в моем GitHub.

******* При запуске сервера я получаю это сообщение об ошибке *******

(python10_env) D:\Online Drives\MDigital\CIT-Letures\python10_env\smart_health_consult>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "D:\Online Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\urls\resolvers.py", line 634, 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\USER\AppData\Local\Programs\Python\Python310\lib\threading.py", line 1009, in _bootstrap_inner
    self.run()
  File "C:\Users\USER\AppData\Local\Programs\Python\Python310\lib\threading.py", line 946, in run
    self._target(*self._args, **self._kwargs)
  File "D:\Online Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\utils\autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "D:\Online Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\management\commands\runserver.py", line 124, in inner_run
    self.check(display_num_errors=True)
  File "D:\Online Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\management\base.py", line 438, in check
    all_issues = checks.run_checks(
  File "D:\Online Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\checks\registry.py", line 77, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "D:\Online Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "D:\Online Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\checks\urls.py", line 67, in _load_all_namespaces
    namespaces.extend(_load_all_namespaces(pattern, current))
  File "D:\Online Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "D:\Online Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\utils\functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "D:\Online Drives\MDigital\CIT-Letures\python10_env\lib\site-packages\django\urls\resolvers.py", line 642, in url_patterns
    raise ImproperlyConfigured(msg.format(name=self.urlconf_name)) from e
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'ml_dp_model.urls' from 'D:\\Online Drives\\MDigital\\CIT-Letures\\python10_env\\smart_health_consult\\ml_dp_model\\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.

Вот ml_dp_model>urls.py **** urls.py *****

from django.urls import path
from . import views

#from .views import index
#from .views import predict

urlpartterns = [
    path('', views.index, name='index'),    
    path('result.html', views.predict, name='predict')
    
]

Здесь находится ml_dp_model>views.py ********* views.py *********

from django.shortcuts import render
# Testing if context can solve circular refference issue.
from django.template import context
# Model related imports
import pandas as pd #install pandas
import pickle
import numpy as np #  helps to manipulate the data

# Create your views here.
def index(request):
    return render(request, 'index.html')

# importing the models using pickle.
    #Loading Naive Bayes Pickle  Model load method 1
nb_pickle = open('./models_store/final_nb_model.pickel','rb+')
nb_model = pickle.load(nb_pickle)
    #Loading RandomForest Pickle Modal load method 1
rf_pickle = open('./models_store/final_rf_model.pickel', 'rb+')
rf_model = pickle.load(rf_pickle)
    #Loading Scala Vector Machine  Pickle  Model load method 2
svm_model = pickle.load(open('./models_store/final_svm_model.pickel', 'rb+'))

# Disease prediction Function:
def predict(request):
    if request.method=='POST':
        symptom_index = {}
        symptom_index['symptom1'] =float(request.POST.get('symptom1')) # Add data in string format to the dictionary
        symptom_index['symptom2'] =float(request.POST.get('symptom2'))
        symptom_index['symptom3'] =float(request.POST.get('symptom3'))
        user_symptoms = pd.DataFrame({'X':symptom_index}).transpose() #think about changing dictionary to list at this line.
        # Using pickle model() to predict
        nb_prediction = nb_model.predict(user_symptoms)[0]
        rf_prediction = rf_model.predict(user_symptoms)[0]
        svm_prediction = svm_model.predict(user_symptoms)[0]
                
        '''
        Making final prediction by taking mode of all predicitions
        '''
        final_prediction = np.mode([rf_prediction, nb_prediction, svm_prediction])
        
        predicted  =  final_prediction

    return render(request,'result.html',{'results':predicted} )

У вас опечатка в urls.py

urlpartterns должно быть urlpatterns :)

Вернуться на верх