def addaccount(request): msg = "An Error occured when adding accoung. Hit the back button and try again." try: a = users.get_object(username__exact=request.POST['new_premail']) msg = "User %s already exists." % request.POST['new_premail'] except users.UserDoesNotExist: if request.POST: data = request.POST.copy() password = users.make_random_password() u = users.create_user(data['new_premail'], data['new_premail'], password) ...