第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

/accounts/signup/ Manager 處的 AttributeError 不可用;

/accounts/signup/ Manager 處的 AttributeError 不可用;

大話西游666 2022-12-20 14:50:51
我有一個(gè)自定義注冊表單SignupForm,用于檢查email自定義用戶對象是否存在CustomUser,如果存在則引發(fā)ValidationError。但是當(dāng)我嘗試提出錯(cuò)誤時(shí),我得到了AttributeError at /accounts/signup/  Manager isn't available; 'auth.User' has been swapped for 'accounts.CustomUser'。這是我的代碼。forms.pyfrom django.contrib.auth.forms import UserCreationFormfrom django import formsfrom django.core.exceptions import ValidationErrorfrom django.contrib.auth import get_user_modelclass SignupForm(UserCreationForm):    def __init__(self, *args, **kwargs):        super(UserCreationForm, self).__init__(*args, **kwargs)    email = forms.CharField(        widget=forms.EmailInput(        attrs={            'class': 'input',            'placeholder': 'bearclaw@example.com'        }    ))    ...    # other fields (username and password)    ...    def clean(self):       User = get_user_model()       email = self.cleaned_data.get('email')       if User.objects.filter(email=email).exists():            raise ValidationError("An account with this email exists.")       return self.cleaned_dataviews.pyfrom django.urls import reverse_lazyfrom django.views.generic import CreateViewfrom .forms import SignupFormfrom .models import CustomUser...# other views and imports...class CustomSignup(CreateView):    form_class = SignupForm    success_url = reverse_lazy('login')    template_name = 'registration/signup.html'models.pyfrom django.db import modelsfrom django.contrib.auth.models import AbstractUserclass CustomUser(AbstractUser):    email = models.EmailField(unique=True)    def __str__(self):        return self.usernamesettings.pyAUTH_USER_MODEL = "accounts.CustomUser"我錯(cuò)過了什么?
查看完整描述

1 回答

?
胡子哥哥

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超6個(gè)贊

基本上你缺少 ModelForm Meta


試試這個(gè)


class SignupForm(UserCreationForm):


    def __init__(self, *args, **kwargs):

        super(UserCreationForm, self).__init__(*args, **kwargs)


    email = forms.CharField(

        widget=forms.EmailInput(

        attrs={

            'class': 'input',

            'placeholder': 'bearclaw@example.com'

        }

    ))


    ...

    # other fields (username and password)

    ...


    def clean(self):

       User = get_user_model()

       email = self.cleaned_data.get('email')

       if User.objects.filter(email=email).exists():

            raise ValidationError("An account with this email exists.")

       return self.cleaned_data


   class Meta:

       model = get_user_model()

       fields = ('username', 'email')


查看完整回答
反對 回復(fù) 2022-12-20
  • 1 回答
  • 0 關(guān)注
  • 105 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號