[英]The current path, POST, didn't match any of these
So, I have a code below:所以,我在下面有一个代码:
newEra/urls.py
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path("",include('mentor.urls')),]
mentor/urls.py导师/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('',views.home_page),
]
my views.py我的意见.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)
home.html主页.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>
But I am getting this error below但我在下面收到此错误
**Using the URLconf defined in NewEra.urls, Django tried these URL patterns, in this order: **使用 NewEra.urls 中定义的 URLconf,Django 按以下顺序尝试了这些 URL 模式:
admin/行政/
The current path, POST, didn't match any of these.**当前路径 POST 与任何这些都不匹配。**
'mentor' file added to the SETTINGS 'mentor' 文件添加到 SETTINGS
URLs are regexes. URL 是正则表达式。
Try:尝试:
urlpatterns = [
path('^/$',views.home_page),
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.