vendredi 29 mai 2015

How to check whether a user created successfully in Django

I was trying Django and I used this code to create a user

from django.shortcuts import render
from django.http import HttpResponse
from django.contrib.auth.models import User    

def register(request):
    user = User.objects.create_user('John', 'lennon@thebeatles.com', 'johnpassword')
    user.last_name = "James"
    user.is_active = True
    status = user.save()
    return HttpResponse(status)

My question is how can I check whether a user is successfully created or not and also to display an error message, if I am unable to create a user. When I run this code, it creates a user but returns a value None

Thanks

Aucun commentaire:

Enregistrer un commentaire