这是我的密码 我不知道错误是从哪里来的。它告诉我 Django使用ehiz.URL中定义的URLconf,按以下顺序尝试了这些URL模式:
管理员/ [name='home'] add/[name='add'] 当前路径get与这些路径都不匹配
Views.py
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return render(request,'base.html',{'name':'Gael'})
def add(request):
val1 = int(request.GET['num1'])
val2 = int(request.GET['num2'])
res = val1 + val2
return render(request, 'result.html',{'result':res})
base.html
{% extends 'main.html' %}
{% block content %}
<h1>hello {{name}}</h1>
<form action="get">
<input type="text" name="num1" placeholder="Enter first number"><br>
<input type="text" name="num2" placeholder="enter second number"><br>
<input type="submit">
</form>
{% endblock %}
result.html
{% extends 'main.html' %}
{% block content %}
the result is : {{result}}
{% endblock %}
url.py
from django.urls import path
from . import views
urlpatterns = [
path('',views.home,name='home'),
path('add/',views.add,name='add')
]
在
<form>
中,您将method="…"
与action="…"
属性混淆。method="…"
指定HTTP请求类型,而action="…"
指定请求将提交到哪个端点因此,您应该与以下人员合作:
不需要
method="get"
,因为默认情况下,表单将通过GET请求提交相关问题 更多 >
编程相关推荐