Django1.11自定义UserCreationForm过滤电子邮件

时间:2018-03-25 02:57:02

标签: python django authentication django-forms

我正在尝试过滤用户的别名。我正在使用Django的userform及其身份验证。

forms.py

from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User

class SignupForm(UserCreationForm):
    email = forms.CharField(
        retuired=True,
        widget=EmailInput(
            attrs={'class':'validate',}
        )
    )

views.py

from django.shortcuts import render,redirect
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import login as auth_login

def signup(req):
    if req.method == "POST":
        form = UserCreationForm(req.POST)
        if form.is_valid():
            user = form.save()
            auth_login(req, user)
            return redirect('home')
    else:
        form = UserCreationForm()
    context = {
        'form':form,
    }
    return render(req, "signup.html", context)

我相信我需要在views.py内部进行过滤。
例如,如果我想过滤不是gmail的别名,他们就无法注册。我该如何过滤电子邮件?

提前致谢!

1 个答案:

答案 0 :(得分:1)

您可以使用override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { let post = storyboard?.instantiateViewController(withIdentifier: "postVC") as! postVC // Why dont use post.postImg = postImgData[indexPath.row]? // Do not use Global vars, because you can change it from anywhere without noticing self.navigationController?.pushViewController(post, animated: true) } 方法。

clean_<field_name>

https://docs.djangoproject.com/en/1.11/ref/forms/validation/#cleaning-a-specific-field-attribute