My Django app is deployed on Heroku and I'm using Postgres there and MySQL for development. I can't get the user to login (manually) and I get this error:
DatabaseError at /login/
current transaction is aborted, commands ignored until end of transaction block
After examining the code, it turned out that the problem happens in the django.contrib.auth.authenticate
Here is my view's code:
if request.method == 'POST':
username = request.POST.get('username')
print username
password = 'none'
try:
user = User.objects.create_user(username, 'none', password)
user.save()
print user
fb_user_id = request.POST.get('fb_user_id')
print fb_user_id
full_name = request.POST.get('full_name')
print full_name
hostname = request.get_host()
invite_link = hostname + '/referal/'+str(short_url.encode_url(int(fb_user_id)))
print invite_link
# Create a UserProfile object that references user.
profile = UserProfile(
user = user,
fb_user_id = fb_user_id,
username = username,
full_name = full_name,
invite_link = invite_link
)
profile.save()
print profile
settings = Setting(user=profile)
settings.save()
print settings
print "success"
return HttpResponse('success')
except:
print "error"
# Authenticate the user
user = authenticate(username=username,password='none')
print user
if user is not None:
print "user is not None: ", user
if user.is_active:
print "loggin user in "
login(request, user)
return HttpResponseRedirect('/')
else:
print user,
print "user is none"
else:
return HttpResponse('not a post ')
return HttpResponse('fail')
When i try to login with registered users, the last thing i see in the log is "error" which is printed in the except
block. In development environment, everything works as expected !
Did anybody run into this problem before?
EDIT Actually the authentication through the admin panel works just fine, and the registration of users works perfectly too.