喜 我不知道为什么我的表格无效! 我试过这个
class SignupForm(forms.Form):
first_name = forms.CharField(required=True, max_length=35)
last_name = forms.CharField(required=True, max_length=35)
username = forms.CharField(required=True, max_length=50)
email = forms.EmailField(required=True)
password = forms.CharField(required=True, min_length=8, max_length=64)
confirm_password = forms.CharField(required=True, min_length=8, max_length=64)
template.html
<form id="signupForm" action="" method="POST" accept-charset="utf-8" class="form" role="form">
{% csrf_token %}
<div class="row">
<div class="col-xs-6 col-md-6">
<input id="first_name" type="text" autocomplete="off" name="firstname" value="" class="form-control input-lg" placeholder="First Name" />
</div>
<div class="col-xs-6 col-md-6">
<input id="last_name" type="text" autocomplete="off" name="lastname" value="" class="form-control input-lg" placeholder="Last Name" />
</div>
</div>
<input id="username" type="text" autocomplete="off" name="username" value="" class="form-control input-lg" placeholder="Choose Username" />
<input id="email" type="text" autocomplete="off" name="email" value="" class="form-control input-lg" placeholder="Your Email" />
<input id="password" type="password" autocomplete="off" name="password" value="" class="form-control input-lg" placeholder="Password" />
<input id="confirm_password" type="password" name="confirm_password" value="" class="form-control input-lg" placeholder="Confirm Password" />
<div class="topmargin active">
<div class="row" style="display: flex;">
<div class="col-xs-5 col-md-5">
<label>I'm </label>
<select name="month" class = "form-control input-lg">
<option value="male">Male</option>
<option value="female">Female</option>
</select>
</div>
<br />
<span class="help-block">By clicking Create my account, you agree to our Terms and that you have read our Data Use Policy, including our Cookie Use.</span>
<button class="btn btn-block signup-btn" type="submit">Create my account</button>
</form>
我认为这是因为我没有将表单传递给模板,但我不想那样做! 它混合了响应式风格 命令是受欢迎的 谢谢
答案 0 :(得分:3)
问题在于:
"* "& "ca"
在表单中,您使用带有下划线的 first_name 和 last_name ,但在输入时,它们没有下划线。
您需要更改输入名称以匹配表单字段:
<input id="first_name" type="text" autocomplete="off" name="firstname" value="" class="form-control input-lg" placeholder="First Name" />
<input id="last_name" type="text" autocomplete="off" name="lastname" value="" class="form-control input-lg" placeholder="Last Name" />