Querying my database to get a user so I can log them out, but getting the above error.
def logout(request):
id = request.session["user_id"]
user = get_object_or_404(User, pk=id)
auth.logout(user)
I'm not trying to to say that User has a session attribute, I telling it that it's primary key is equal to the number held in the session.
If you want to use a database-backed session, you need to add 'django. contrib. sessions' to your INSTALLED_APPS setting. Once you have configured your installation, run manage.py migrate to install the single database table that stores session data.
Sessions are the mechanism used by Django (and most of the Internet) for keeping track of the "state" between the site and a particular browser. Sessions allow you to store arbitrary data per browser, and have this data available to the site whenever the browser connects.
As of Django 1.8, any call to flush() will log out the user. From the docs: Changed in Django 1.8: Deletion of the session cookie is a behavior new in Django 1.8. Previously, the behavior was to regenerate the session key value that was sent back to the user in the cookie.
auth.logout()
expects request
not a user instance. Assuming you're talking about django.contrib.auth
https://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.logout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With