Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Notifications
Mark all as read
Q&A

Need help in migrating a Python2 custom middleware to current Python3 version

+0
−2
class ExtendUserSession(MiddlewareMixin):

    """
    Extend authenticated user's sessions so they don't have to log back in
    following 15 minutes (set by Django's default `SESSION_COOKIE_AGE` setting).
    """
    def process_request(self, request, get_response):
        current_user = request.user
        # Only extend the session for auth'd users
        if request.user.is_authenticated:
            reason = CsrfViewMiddleware('get_response').process_view(request, None, (), {})
            if reason:
                # process_view returns HTTPException
                pass
        else:
                # process_view returns None - No error on HTTP request from CSRF middleware verification
            request.session.set_expiry(86400)

In this method, the admin can log in inside the website but after any post request, the session gets expires and returns to the login page

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

3 comment threads

Post Feedback (1 comment)
Hii I have migrated my code 90 percent successfully and I was tucked only in this one..And I am new t... (1 comment)
Did you check the [Porting to Python3](https://docs.djangoproject.com/en/1.11/topics/python3/) docs? ... (1 comment)

0 answers

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!

Like what we're doing? Support us! Donate