运行服务器时,我收到一条错误消息,提示我所有的URL路径均无效。我检查了拼写,语法,甚至复制并粘贴都没有用。我只希望它运行。
我试图更正所有的拼写,语法。
我正在Raspberry Pi 3 B上运行一个简单的Django服务器
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name="index"),
path('suggest/', views.OwO, name="OwO"),
]
我也尝试过
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name="index"),
path('suggest', views.OwO, name="OwO"),
]
我的观点
from django.shortcuts import render
from django.http import HttpResponse
from .forms import suggest
from .models improt message
# Create your views here.
def index(request):
form = suggest()
return render(request, 'index.html' {'form':form})
def OwO(request):
if request.method == 'POST':
form = sugest(request.POST)
if form.is_valid():
name = form.cleaned_data['name']
UwU = form.cleaned_data['messgae']
a = message(form_name=name, form_message=UwU)
a.save()
return HttpResponse("Thank you " + name + "!")
else:
Return HttpResponse("OwO")
例外:
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.5/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 "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/django/utils/autoreload.py", line 54, in wrapper
fn(*args, **kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/home/pi/.local/lib/python3.5/site-packages/django/core/management/base.py", line 390, in check
include_deployment_checks=include_deployment_checks,
File "/home/pi/.local/lib/python3.5/site-packages/django/core/management/base.py", line 377, in _run_checks
return checks.run_checks(**kwargs)
File "/home/pi/.local/lib/python3.5/site-packages/django/core/checks/registry.py", line 72, in run_checks
new_errors = check(app_configs=app_configs)
File "/home/pi/.local/lib/python3.5/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/home/pi/.local/lib/python3.5/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/home/pi/.local/lib/python3.5/site-packages/django/utils/functional.py", line 80, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/pi/.local/lib/python3.5/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 'Suggest.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.
答案 0 :(得分:0)
您确定此代码正在运行吗?
我可以看到一些错误,例如Return
(必须是小写)或sugest
(缺少一个字母g)。