简体   繁体   English

为什么 request.GET.get() 返回 'None' 并且 html 元素的值在 URL 中不可见

[英]why request.GET.get() returns 'None' and value of html element is not visible in URL

index.html索引.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HELLO</title>
</head>
<body>
    <form action="/removepunc", method="get">
        <input type="text",name='text' value="Hello,Django" />
        <input type="submit">
    </form>
</body>
</html>

views.py视图.py

from django.http import HttpResponse
from django.shortcuts import render


def index(request):
    return render(request,'index.html')

def removepunc(request):
    print("Text is :"+request.GET.get('text','default'))
    return HttpResponse("Hello")

urls.py网址.py

from django.contrib import admin
from django.urls import path
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',views.index,name='index'),
    path('removepunc',views.removepunc,name='rempunc')

]

This is first screen after run the code这是运行代码后的第一个屏幕

When I click on submit in Url it did not show "hello django"当我点击 Url 中的提交时,它没有显示“hello django”

Also in terminal it print default not "hello django"同样在终端它打印默认不是“hello django”

There is a comma in your <input> box between "text" and name . <input>框中的"text"name之间有一个逗号。

The <input> tag should thus look like: <input>标签应该如下所示:

<input type="text" name="text" value="Hello,Django" />

not:不是:

<input type="text",name='text' value="Hello,Django" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM