[英]The current path, POST, didn't match any of these
所以,我在下面有一个代码:
newEra/urls.py
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path("",include('mentor.urls')),]
导师/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('',views.home_page),
]
我的意见.py
from django.shortcuts import render,redirect
from .models import *
from .forms import *
def home_page(request):
todo = ToDo.objects.all()
form = ToDoForms()
if request.method == 'POST':
form = ToDoForms(request.POST)
if form.is_valid():
form.save()
return redirect('')
context = {'todo' : todo, 'form':form}
return render(request, 'home.html',context)
主页.html
<h1>To-Do list</h1>
<form action="POST" method="/">
{% csrf_token %}
{{form.name}}
<input type="submit" value="Create task" >
</form>
<ul>
{% for to in todo %}
<li>{{ to }}</li>
{% endfor %}
</ul>
但我在下面收到此错误
**使用 NewEra.urls 中定义的 URLconf,Django 按以下顺序尝试了这些 URL 模式:
行政/
当前路径 POST 与任何这些都不匹配。**
'mentor' 文件添加到 SETTINGS
URL 是正则表达式。
尝试:
urlpatterns = [
path('^/$',views.home_page),
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.