Overwrite Django's logout method

1

I have activated in settings SESSION_EXPIRE_AT_BROWSER_CLOSE so that when the browser is closed the session is closed.

I have a function so that when the session closes I do some tasks in a table of the database, it works correctly.

But it only works when the LOGOUT option is given, when I close the browser it does not work.

Then I think, when the session closes when the browser is closed, does not it call the LOGOUT function? How could I do to force him to go through LOGOUT and perform the task I want?

    
asked by David 12.09.2017 в 20:09
source

2 answers

0

It's a good question, but first we must understand why it does not work.

When you create the logout view, what you are doing is creating a function or class that is called every time you enter that view and therefore the code that you specified is executed. But in the case of expire session at browser close, it is different why the view no longer comes into play here, django takes part in this and sends the logout when the browser is closed.

Solution

Well here I'm not so sure, but what you can do is modify directly in the django files, here I leave a link that shows the function link

You can try adding the code inside the function

    
answered by 13.09.2017 / 17:34
source
1

Hello friend, the only thing that I have found is to do it directly from the URL in the file urls.py so:

    from django.contrib.auth import views as auth_views
    urlpatterns = [

        url(r'^$', inicio, name="inicio"),
        url(r'^login/$', auth_views.login, name='login'),
        url(r'^logout/$', auth_views.logout,  {'next_page': '/site/'}, name='logout'),

So you can direct the logout where you want, I hope it serves you.

    
answered by 16.05.2018 в 21:26