Вопрос
Когда я запустил веб-сервер Django с помощью 'python manager.py runserver', произошла какая-то ошибка.Похоже, что [django.core.exceptions.ImproperlyConfigured: включенный URLconf 'myproject.urls', похоже, не содержит никаких шаблонов.Если вы видите допустимые шаблоны в файле, то проблема, вероятно, вызвана циклическим импортом.]
Дерево проекта выглядит следующим образом:
root project
myapp:
__init__.py
urls.py
views.py
myproject:
__init__.py
urls.py
settings.py
uwsgi.py
manage.py
__init__.py
myproject / urls.py code:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.urls', namespace='myapp')),
]
myapp / urls.py код:
from myapp import views
from django.urls import path
urlpatterns = [
# path('/', views.Home.as_view(), name='home'),
path('signup/', views.Signup.as_view(), name='signup'),
path('signin/', views.Signin.as_view(), name='signin'),
path('signout/', views.Signout.as_view(), name='signout'),
path('make_csr/', views.MakeCSR.as_view(), name='make_csr'),
path('upload_csr/', views.UploadCSR.as_view(), name='upload_csr'),
path('publish_cer/', views.PublishCER.as_view(), name='publish_cer'),
]
Подробное сообщение об ошибке:
(cert_mgmt) C:\Users\wenca\Desktop\Python\virtual_environment\cert_mgmt\python\Src>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 "C:\Program Files\Python37\lib\site-packages\django\urls\resolvers.py", line 581, 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:\Program Files\Python37\lib\threading.py", line 917, in _bootstrap_inner
self.run()
File "C:\Program Files\Python37\lib\threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "C:\Program Files\Python37\lib\site-packages\django\utils\autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\django\core\management\commands\runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "C:\Program Files\Python37\lib\site-packages\django\core\management\base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "C:\Program Files\Python37\lib\site-packages\django\core\management\base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "C:\Program Files\Python37\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "C:\Program Files\Python37\lib\site-packages\django\core\checks\urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "C:\Program Files\Python37\lib\site-packages\django\core\checks\urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "C:\Program Files\Python37\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Program Files\Python37\lib\site-packages\django\urls\resolvers.py", line 579, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Program Files\Python37\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Program Files\Python37\lib\site-packages\django\urls\resolvers.py", line 572, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Program Files\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\wenca\Desktop\Python\virtual_environment\cert_mgmt\python\Src\myproject\urls.py", line 7, in <module>
path('', include('myapp.urls', namespace='myapp')),
File "C:\Program Files\Python37\lib\site-packages\django\urls\conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "C:\Program Files\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\wenca\Desktop\Python\virtual_environment\cert_mgmt\python\Src\myapp\urls.py", line 1, in <module>
from myapp import views
File "C:\Users\wenca\Desktop\Python\virtual_environment\cert_mgmt\python\Src\myapp\views.py", line 21, in <module>
class Signup(View):
File "C:\Users\wenca\Desktop\Python\virtual_environment\cert_mgmt\python\Src\myapp\views.py", line 26, in Signup
'post_link': reverse('myapp:signup'),
File "C:\Program Files\Python37\lib\site-packages\django\urls\base.py", line 58, in reverse
app_list = resolver.app_dict[ns]
File "C:\Program Files\Python37\lib\site-packages\django\urls\resolvers.py", line 512, in app_dict
self._populate()
File "C:\Program Files\Python37\lib\site-packages\django\urls\resolvers.py", line 446, in _populate
for url_pattern in reversed(self.url_patterns):
File "C:\Program Files\Python37\lib\site-packages\django\utils\functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Program Files\Python37\lib\site-packages\django\urls\resolvers.py", line 588, in url_patterns
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf 'myproject.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.