<環境>
・django バージョン: 3.2.5
・pythonバージョン :3.8.12
<やりたい事>
・アカウント登録ページからアカウントの情報DBに登録するDjangoの機能を問題なく機能させたい。
accounts.urlsにてルーティングしてacccounts.viewsでレンダリング
↓
<現状>
・下記のようなエラーが出てるためアカウントの登録ができない。
詳細は調べたけど全然把握できていません。
・settings.pyにて『AUTH_USER_MODEL='accounts.CustomUser'』、
『INSTALLED_APPS = [ 'accounts.apps.AccountsConfig', ]』を設定済み。
<エラー内容>
Internal Server Error: /signup/ Traceback (most recent call last): File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\core\handlers\exception.py", line 47, in inner response = get_response(request) File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\views\generic\base.py", line 70, in view return self.dispatch(request, *args, **kwargs) File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\views\generic\base.py", line 98, in dispatch return handler(request, *args, **kwargs) File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\views\generic\edit.py", line 172, in post return super().post(request, *args, **kwargs) File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\views\generic\edit.py", line 141, in post if form.is_valid(): File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\forms\forms.py", line 175, in is_valid return self.is_bound and not self.errors File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\forms\forms.py", line 170, in errors self.full_clean() File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\forms\forms.py", line 374, in full_clean self._post_clean() File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\contrib\auth\forms.py", line 117, in _post_clean super()._post_clean() File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\forms\models.py", line 413, in _post_clean self.instance.full_clean(exclude=exclude, validate_unique=False) File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\db\models\base.py", line 1223, in full_clean self.clean() File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\contrib\auth\models.py", line 371, in clean self.email = self.__class__.objects.normalize_email(self.email) File "C:\Users\user\anaconda3\envs\django_env\lib\site-packages\django\db\models\manager.py", line 187, in __get__ raise AttributeError( AttributeError: Manager isn't available; 'auth.User' has been swapped for 'accounts.CustomUser'
<コード>
django
apps.py
python
1from django.apps import AppConfig 2 3 4class AccountsConfig(AppConfig): 5 default_auto_field = 'django.db.models.BigAutoField' 6 name = 'accounts'
forms.py
python
1from django.contrib.auth.forms import UserCreationForm 2from .models import CustomUser 3 4class CustomUserCreationForm(UserCreationForm): 5 ''' 6 UserCreationFormのサブクラス 7 ''' 8 model =CustomUser 9 fields = ('username','email','password1','password2')
models.py
python
1from django.db import models 2from django.contrib.auth.models import AbstractUser 3# Create your models here. 4 5 6class CustomUser(AbstractUser): 7 ''' 8 Userモデルを継承したカスタムモデル 9 ''' 10 pass
urls.py
python
1from django.urls import path 2from . import views 3 4 5app_name='accounts' 6 7urlpatterns=[ 8 path('signup/',views.SignUpView.as_view(),name='signup'), 9 path('signup_success/',views.SignUpSuccessView.as_view(),name='signup_success'), 10]
views.py
python
1from django.shortcuts import render 2from django.views.generic import CreateView,TemplateView 3from django.urls import reverse_lazy 4from .forms import CustomUserCreationForm 5 6 7# Create your views here. 8 9class SignUpView(CreateView): 10 form_class=CustomUserCreationForm 11 template_name="signup.html" 12 success_url=reverse_lazy('accounts:signup_success') 13 14 def form_valid(self,form): 15 user=form.save() 16 self.object=user 17 return super().form_valid(form) 18 19class SignUpSuccessView(TemplateView): 20 template_name="signup_success.html"
わかる方いれば教えてください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。