python manage.py runserver
引发异常。如何在本地主机上获取启动网页?
我尝试了Django Slack社区小组,还尝试了关于Django Framework中“ RecursionError”的StackOverflow问题,但答案不确定且令人困惑。
python3 manage.py运行服务器 正在执行系统检查...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x102b926a8>
Traceback (most recent call last):
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/utils/autoreload.py", line 225, in wrapper fn(*args, **kwargs)
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run self.check(display_num_errors=True)
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/core/management/base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/core/management/base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/core/checks/registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 67, in _load_all_namespaces
namespaces.extend(_load_all_namespaces(pattern, current))
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 67, in _load_all_namespaces
namespaces.extend(_load_all_namespaces(pattern, current))
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 67, in _load_all_namespaces
namespaces.extend(_load_all_namespaces(pattern, current))
[Previous line repeated 986 more times]
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 59, in _load_all_namespaces
':'.join(parents + (url.namespace,)) for url in url_patterns
File "/Users/kuldeep/env/lib/python3.7/site-packages/django/core/checks/urls.py", line 60, in <listcomp>
if getattr(url, 'namespace', None) is not None
RecursionError: maximum recursion depth exceeded while calling a Python object
我期望飞行的火箭使我对本地主机上的祝贺消息充满信心。
mysite / urls.py文件:
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('polls/', include('polls.urls')),
path('admin/', admin.site.urls),
]
polls / urls.py文件:
from django.urls import include, path
from django.contrib import admin
from . import views
urlpatterns = [
path('polls/', include ('polls.urls')),
path ('admin/', admin.site.urls),
]
polls / views.py代码:
from django.shortcuts import render
# Create your views here.
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You are at the polls index")
答案 0 :(得分:2)
查看您的urlpatterns
的 polls / urls.py 代码,其中包括自身,这会导致无休止的循环。
您的 polls / urls.py 应该包含特定于 polls 应用的子路径。由于此应用只有一个视图,因此您可能只需要一个路径:
path('', views.index)
请记住, my_site / urls.py 包含在polls/
路径下,因此获取index
视图的完整路径为:“ / polls / “。
您可能正在做Django教程,请检查代码here