这里的新手总数。我正在为我的主页创建自定义注册表单。我做了以下事情:
class RegForm(forms.Form): email = forms.EmailField() password=forms.PasswordInput() password2=forms.PasswordInput() phone= forms.CharField(max_length=10)
<div class="form-group">
{{ form.email.errors }}
<label for="{{form.email.id_for_label}}">
<b>Email</b>
</label>
{{ form.email }}
</div>
<div class="form-group">
{{ form.non_field_errors }}
<label for="{{ form.password.id_for_label }}">
<b>Password</b>
</label>
{{ form.password }}
</div>
<div class="form-group">
{{ form.non_field_errors }}
<label for="register_password2">
<b>Re-enter Password</b>
</label>
{{ form.password2 }}
</div>
<div class="form-group">
{{ form.non_field_errors }}
<label for="phone">
<b>Phone Number</b>
</label>
{{ form.phone }}
</div>
def register(request): registered = False if request.method == 'POST': form = RegForm(request.POST) if form.is_valid(): return HttpResponseRedirect('/thanks/') else: form=RegForm() return render(request,'index.html',{'form':form})
我做错了什么?我不明白。请帮忙。
答案 0 :(得分:5)
问题与pycharm上的src root和文件views.py和urls.py中缺少import有关。