How to create a user in Django?

后端 未结 4 879
不思量自难忘°
不思量自难忘° 2020-12-12 18:37

I\'m trying to create a new User in a Django project by the following code, but the highlighted line fires an exception.

def createUser(request):
    userNam         


        
4条回答
  •  春和景丽
    2020-12-12 19:26

    The correct way to create a user in Django is to use the create_user function. This will handle the hashing of the password, etc..

    from django.contrib.auth.models import User
    user = User.objects.create_user(username='john',
                                     email='jlennon@beatles.com',
                                     password='glass onion')
    

提交回复
热议问题