Django login() function works in production but not in development

49 views
Skip to first unread message

pieceof...@gmail.com

unread,
May 14, 2018, 6:55:38 PM5/14/18
to Django users
Hey All,

So I have a django project in a directory for production.  I have the same exact project in a separate repository for development.  I literally have copied and pasted my project over and the only changes I have made are switching debug from false to true.  So my project has the same database, same code, everything.  When I start up my local copy and go to login, the login function does not work.  Below is my simple login view.  My code returns the print statement 'User is active' when I sign in with a user on my project page; however, my user never gets logged in during the next step.  Does anyone have any clues as to why this might be?  Thanks for your time.


views.py
def friend_login(request):
   
if request.method == 'POST':
        username
= request.POST.get('username')
        password
= request.POST.get('password')
        user
= authenticate(username=username, password=password)

       
if user:
           
if user.is_active:
               
# the User model is valid and active, so we can log the user in
               
print 'User is active'
                login
(request, user)
               
return HttpResponseRedirect(reverse('main:index'))
           
else:
               
# An inactive account was used - no logging in!
               
print 'User is inactive'
               
return render(request, 'friends/inactive.html', {'user':user})
       
else:
           
# Bad login credentials
           
return HttpResponse("Invalid login details supplied.")
   
else:
       
# Not a POST, so simply display the login form
       
return render(request, 'friends/login.html', {})


童话root

unread,
May 14, 2018, 9:00:39 PM5/14/18
to django...@googlegroups.com
Hello there,
I think the reason is that your login session is stored in the database. The two programs share a set of databases, so the login status is synchronized.

The corresponding solution, then copy a set of databases, and clear the current login session.

Hope you can solve your problem.
best wishes.
Tonghua

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8821e5bc-0a14-47e2-82bd-8b229daaf50d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pieceof...@gmail.com

unread,
May 16, 2018, 3:18:54 PM5/16/18
to Django users


Hey, Tonghua.

Could you elaborate more on the shared set of databases?  So yes, the login session is stored in the database.  But wouldn't my two applications have two distinct database files?  My reasoning would be due to having two distinct locations for my in-development copy and in-production copy.

Thanks for your time,
K

Melvyn Sopacua

unread,
May 19, 2018, 5:43:15 PM5/19/18
to django...@googlegroups.com
On dinsdag 15 mei 2018 00:55:38 CEST pieceof...@gmail.com wrote:
> My code
> returns the print statement 'User is active' when I sign in with a user on
> my project page; however, my user never gets logged in during the next
> step.

How did you determine the user doesn't get logged in?
--
Melvyn Sopacua

pieceof...@gmail.com

unread,
May 21, 2018, 12:28:55 PM5/21/18
to Django users
Thanks, I probably should elaborate on that.  I determine the user does not get logged in through the logic of my template language.  I have {% if user.is_authenticated %} do something {% else %} do something else {% endif %} where user is passed through the context dictionary of my corresponding view displayed above.

pieceof...@gmail.com

unread,
May 21, 2018, 1:32:28 PM5/21/18
to Django users
I should elaborate even further.. The 'do something' does not show, instead the 'do something else' shows.
Reply all
Reply to author
Forward
0 new messages