我的视图没有收到我从登录表单发送的任何POST数据.
要测试提交,我想将电子邮件字段输出到浏览器.
从视图返回的输出是 None
的login.html
<form action="/login_email/" method="POST">
{% csrf_token %}
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" placeholder="Email">
</div>
<div class="form-group">
<label for="email">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-info">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
views.py
def login_email(request):
if request.method == 'POST':
email = request.POST.get('email')
password = request.POST.get('password')
return HttpResponse(email)
Run Code Online (Sandbox Code Playgroud)
输入标记中没有名称字段.
将您的html更改为类似的内容...请注意带有输入标记的name属性,这是最重要的.
<form action="/login_email/" method="POST">
{% csrf_token %}
<div class="form-group">
<label for="email">Email address</label>
<input name="email" type="email" class="form-control" id="email" placeholder="Email">
</div>
<div class="form-group">
<label for="email">Password</label>
<input name="password" type="password" class="form-control" id="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-info">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
627 次 |
| 最近记录: |