python - Request.POST.get 在 django 中对我不起作用,返回默认值
问题描述
我正在尝试从 django 中的 html 表单获取输入,python 代码如下:
def add(request):
n = request.POST.get('Username', 'Did not work')
i = Item(name=n,price=0)
i.save()
return render(request,'tarkovdb/test.html')
第二张图片是我的html代码:
<html>
<head>
<meta charset="UTF-8"›
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384—Vkoo8x4CGs0 OPaXtkKtu6ug5T0eNV6gBiFeWPGFN9Muh0f23Q9Ifjh" crossorigin="anonymous">
<title>Tarkov Database Web App</title>
</head>
<body>
<h1>This is the page to add items</h1>
<li><a href="{% url 'tarkovdb:index' s'6}">List of Items in DataBase</a></li>
<form>
<div class="form—group">
<label for&username'> Username: </lable>
<input type&text' name='Username' id.'username'> <br><br>
</div>
<button type="submit" class="btn btn—primary">Submit</button>
</form>
解决方案
推荐阅读
- android - Log.i() 是什么意思
- json - 如何使用 Laravel Scout Elasticsearch Driver 从 Elasticsearch 获取自定义文档字段?
- x86 - i386 中的哪个寄存器存储 CPL?
- javascript - 无法在 Firefox for Cross-Origin 资源中访问 Content-Length 标头
- java - 华为特定的操作系统风格在我的文件夹中创建奇怪的文件
- visual-studio-code - 如何以扩展作者身份调试以下内容:扩展主机意外终止。代码:3221225477 信号:空
- c# - 如何在线程中播放声音?
- c# - 从 xml 文档中删除节点
- python - Apply() 函数无法正常工作
- powershell - PowerShell 输出文件