电子邮件地址未在Django注册表中显示

时间:2015-11-27 21:03:04

标签: django forms email registration

我有一个非常基本的注册表单,询问用户他的用户名和密码(两次)。 现在我想为电子邮件地址添加一个字段,因为我想添加'重置密码'功能。

我发现以下代码要添加电子邮件字段: https://gist.github.com/schwuk/2725286 我正在使用这种扩展形式。

但是,电子邮件字段未显示在我的注册表单中。 此表单的模板如下所示:

{% extends "base.html" %}
{% block title %}Create an account{% endblock %}
{% block content %}
<h1>Create an account</h1>
<form action="/app/register/" method="post">
{% csrf_token %}
  {{ form.as_p }}
  <input type="submit" value="Create the account">
 </form>
{% endblock %}

这是views.py的相关部分:

from django.http import HttpResponse, HttpResponseRedirect
from django.template import RequestContext, loader
from django.shortcuts import render,get_object_or_404 
from .forms import DocumentForm, MyUserCreationForm
from django.contrib.auth.decorators import login_required
from django.contrib import auth

def auth_view(request):
    username = request.POST.get('username', '')
    password = request.POST.get('password', '')
    user = auth.authenticate(username = username, password = password)      

    if user is not None:
        auth.login(request, user)
        return HttpResponseRedirect('/app/home/')
    else:
        return HttpResponseRedirect('/accounts/invalid')


def register(request):
    if request.method == 'POST':
        form = MyUserCreationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            return HttpResponse("Registration was succesful")
    else:
        form = MyUserCreationForm()
        return render(request, "registration/register.html", {
                    'form': form,})

0 个答案:

没有答案