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
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

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

Post

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

+0
−3
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

History
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)
Hii I have migrated my code 90 percent successfully and I was tucked only in this one..And I am new t...
roronoa_zoroDR‭ wrote almost 2 years ago

Hii I have migrated my code 90 percent successfully and I was tucked only in this one..And I am new to Django, so I have no idea how to correct this code