django - 如何在 Django-Registration 中使用不同的表单

标签 django django-registration

Django-Registration 在 forms.py 文件中有几个表单类。一是“类 RegistrationFormTermsOfService(RegistrationForm) ..

我需要对 Django 注册代码的其余部分进行哪些更改才能在我的注册流程中启用此表单而不是 RegistrationForm?

最佳答案

更新接受的答案以符合 Django 1.5 和最新版本的 django-registration:

在 urls.py 中:

from registration.forms import RegistrationFormTermsOfService
from registration.backends.default.views import RegistrationView

urlpatterns = patterns('',
    url(r'^accounts/register/$', RegistrationView.as_view(form_class=RegistrationFormTermsOfService), name='registration_register'),
    # your other URLconf stuff follows ...
)

然后更新registration_form.html模板并添加tos字段,例如:

<p>
<label for="id_tos">I accept the terms of service</label>
{% if form.tos.errors %}
    <p class="errors">{{ form.tos.errors.as_text }}</p>
{% endif %}
{{ form.tos }}
</p>

关于django - 如何在 Django-Registration 中使用不同的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6414926/

相关文章:

python - 如何使 Django 中传递参数的 url 起作用?

Django - Ajax 注册

python - Django React axios 发布请求 : how to get csrftoken cookie?

python - Django-registration 重新发送带有新代码的激活邮件

python - django-注册模块不发送电子邮件

django - {% url %} 给了我 NoReverseMatch 错误,而 reverse() 返回 url 就好了。为什么?

django - 无反向匹配 : in the password reset form in Django-registration?

javascript - Django/Python/toDataURL 返回带有来自 toDataURL 的字符串的响应

django - Google 网站站长工具出现 HttpResponse 错误

python - 为什么 Django 找不到我的模板