我正在使用Django创建一个登录。我在if request.method == 'POST':
遇到了问题。将表单提交到下面的脚本时,表单会重定向到else语句(转到google)而不是post方法。我的模板文件如下。
Django脚本:
def signup(request):
username = email = password = repassword = ''
try:
redirect_to = request.GET.get('next','/')
except ValueError:
redirect_to = "/"
if request.method == 'POST':
form = SignupForm(request.POST)
if form.is_valid():
username = form.cleaned_data['username']
email = form.cleaned_data['email']
password = form.cleaned_data['password']
repassword = form.cleaned_data['repassword']
else:
return HttpResponseRedirect('http://www.google.com/')
return render(request,'signup.html',{'form':form})
模板文件:
{% extends "base.html" %}
{% block title %}Sign Up{% endblock %}
{% block content %}
<br></br>
<div class = "container">
<form action="/signup/" enctype="multipart/form-data" method="post">
<br></br>
<div class="control-group">
<p>
USERNAME
</p>
<p>
<input type="text" name = "username" value = "" id ="username"/>
</p>
</div>
<div class="control-group">
<p>
EMAIL
</p>
<p>
<input type="text" name = "email" value = "" id= "email"/>
</p>
</div>
<div class="control-group">
<p>
PASSWORD
</p>
<p>
<input type="password" name = "password" value="" id="password"/>
</p>
</div>
<div class="control-group">
<p>
RE-ENTER PASSWORD
</p>
<p>
<input type="password" name = "repassword" value="" id="repassword" />
</p>
</div>
<div class="control-group">
<input type="submit" class="btn btn-danger btn-primary " value="Sign me Up!"/>
</div>
</form>
</div>
{% endblock content %}
感谢您的帮助。