我正在使用django 1.8来创建登录表单。但是包含注册表单的模板无法正确呈现。
我的views.py
class SignUpView(CreateView):
RegistrationForm = UserCreationForm
fields = ['username','password1','password2']
model = User
template_name = 'accounts/signup.html'
我的forms.py
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.forms import AuthenticationForm
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, ButtonHolder, Submit
class RegistrationForm(UserCreationForm):
def __init__(self, *args, **kwargs):
super(RegistrationForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.layout = Layout(
'username',
'password1',
'password2',
ButtonHolder(
Submit('register', 'Register', css_class='btn-primary')
)
)
signup.html
{% extends 'layouts/base.html' %}
{% load crispy_forms_tags %}
{% block title %}Register | {{ block.super }}{% endblock %}
{% block headline %}<h1>Registration form</h1>{% endblock %}
{% block content %}
{% crispy form %}
{% endblock %}
模板呈现但没有提交按钮。我无法弄清问题是什么。
答案 0 :(得分:4)
您的SignUpView
未指定应呈现的表单,您需要添加form_class
属性。
class SignUpView(CreateView):
form_class = RegistrationForm
model = User
template_name = 'accounts/signup.html'