【发布时间】:2021-06-01 09:04:13
【问题描述】:
这很不寻常。代码运行良好,但突然出现此错误:
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\HP\Desktop\Ecommerce\env\lib\site-packages\django\urls\resolvers.py", line 589, 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\hp\appdata\local\programs\python\python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "c:\users\hp\appdata\local\programs\python\python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\HP\Desktop\Ecommerce\env\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\HP\Desktop\Ecommerce\env\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "C:\Users\HP\Desktop\Ecommerce\env\lib\site-packages\django\core\management\base.py", line 395, in check
include_deployment_checks=include_deployment_checks,
File "C:\Users\HP\Desktop\Ecommerce\env\lib\site-packages\django\core\management\base.py", line 382, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Users\HP\Desktop\Ecommerce\env\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Users\HP\Desktop\Ecommerce\env\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "C:\Users\HP\Desktop\Ecommerce\env\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "C:\Users\HP\Desktop\Ecommerce\env\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\HP\Desktop\Ecommerce\env\lib\site-packages\django\urls\resolvers.py", line 596, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'backend.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.
我的后端.urls
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('base.urls')),
]
我的 base.url:
from django.urls import path
from . import views
urlpatterns = [
path('', views.getRoutes, name='getRoutes'),
]
我的基地/views.py
from django.shortcuts import render
from django.http import JsonResponse
from .products import products
# Create your views here.
def getRoutes(request):
routes = [
'/api/products/',
'/api/products/create/',
'/api/products/upload',
'/api/products/<id>/reviews/',
'/api/products/top/',
'/api/products/<id>/',
'/api/products/delete/<id>',
'/api/products/<update>/<id>/',
]
return JsonResponse(routes, safe=False)
我使用 django 很长时间了,现在从来没有见过这个错误,确切的代码运行良好,但是当我在视图中定义第二个 func 时,发生了错误,我删除了那个 func 但错误没有出现。我已经尝试了所有答案,请帮助
【问题讨论】:
-
请发布完整的回溯。
-
嗨威廉我已经发布了回溯,请检查。我认为这是 IDE 问题
标签: django django-views django-urls