您好我在django 1.7中使用了用户的用户名和密码,但我收到了错误 - '经理'对象没有属性' create_user'
my views.py
def register(request):
if request.method == 'POST':
form = UserForm(request.POST)
if form.is_valid():
post = request.POST
username = post['username']
email = post['email']
password = post['password']
user = User.objects.create_user(username, email, password)
return redirect('/student/lastpage')
else:
form = UserForm()
return render(request, 'student/register.html', {'form': form})
my models.py
class User(models.Model):
username = models.CharField(max_length=20)
password = models.CharField(max_length=30)
email = models.CharField(max_length=50)
def __str__(self):
return self.username
class UserForm(ModelForm):
class Meta:
model = User
fields = '__all__'
感谢任何帮助
提前致谢
答案 0 :(得分:4)
默认ModelManager
没有create_user
方法。将适当的经理设置为User
课程。您还需要继承AbstractBaseUser类而不是models.Model
:
from django.contrib.auth.models import AbstractBaseUser, UserManager
class User(AbstractBaseUser):
...
objects = UserManager()