当用户想要注册时,我的网站显示此错误:
管理器不可用; “ auth.User”已被交换 'Log.CUstomUser'
我在模型中使用import AbstractUser
我使用Django freamwork python
型号:
from __future__ import unicode_literals
from django.contrib.auth.models import AbstractUser ,
from django.db import models
# Create your models here.
class CustomUser(AbstractUser):
country = models.CharField(max_length=200)
number = models.IntegerField(default=1)
age = models.IntegerField(default=1)
查看:
from __future__ import unicode_literals
from .forms import Register
from django.shortcuts import render , render_to_response
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
# Create your views here.
@csrf_exempt
def Home(request):
if request.method == "POST":
form = Register(request.POST)
if form.is_valid():
form.save()
return HttpResponse("Greate")
else:
form = Register()
return render_to_response('home.html' , {'form':form})
表格:
from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import CustomUser
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
class Register(UserCreationForm):
email = forms.EmailField(required = True)
number = forms.IntegerField()
age = forms.IntegerField()
class meta:
model = User
field = (
'number',
'age',
'username',
'firstname',
'lastname',
'email',
'password1',
'password2'
)
请帮我解决错误。
答案 0 :(得分:0)
您是否在设置中更改了此变量?
AUTH_USER_MODEL = 'yourapp.CustomUser'
您可以获得there
的更多详细信息答案 1 :(得分:0)
我是django的新用户,但我对您的错误有一个想法,也许会有所帮助。
尝试如下替换Form.py中的model = CustomUser
而不是model=User
:
from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import CustomUser
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
class Register(UserCreationForm):
#blah blah
class meta:
model = CustomUser #hereeeeee
field = (
#your field
)