Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 606721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:17:03+00:00 2026-05-13T17:17:03+00:00

I have a Django app. When logged in as an admin user, I want

  • 0

I have a Django app. When logged in as an admin user, I want to be able to pass a secret parameter in the URL and have the whole site behave as if I were another user.

Let’s say I have the URL /my-profile/ which shows the currently logged in user’s profile. I want to be able to do something like /my-profile/?__user_id=123 and have the underlying view believe that I am actually the user with ID 123 (thus render that user’s profile).

Why do I want that?

Simply because it’s much easier to reproduce certain bugs that only appear in a single user’s account.

My questions:

  1. What would be the easiest way to implement something like this?

  2. Is there any security concern I should have in mind when doing this? Note that I (obviously) only want to have this feature for admin users, and our admin users have full access to the source code, database, etc. anyway, so it’s not really a “backdoor”; it just makes it easier to access a user’s account.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:17:03+00:00Added an answer on May 13, 2026 at 5:17 pm

    I solved this with a simple middleware. It also handles redirects (that is, the GET parameter is preserved during a redirect). Here it is:

    class ImpersonateMiddleware(object):
        def process_request(self, request):
            if request.user.is_superuser and "__impersonate" in request.GET:
                request.user = models.User.objects.get(id=int(request.GET["__impersonate"]))
    
        def process_response(self, request, response):
            if request.user.is_superuser and "__impersonate" in request.GET:
                if isinstance(response, http.HttpResponseRedirect):
                    location = response["Location"]
                    if "?" in location:
                        location += "&"
                    else:
                        location += "?"
                    location += "__impersonate=%s" % request.GET["__impersonate"]
                    response["Location"] = location
            return response
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 335k
  • Answers 335k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ah I think a understand now. Have a look if… May 14, 2026 at 3:36 am
  • Editorial Team
    Editorial Team added an answer pairs [] = [] pairs xs = zip xs (tail… May 14, 2026 at 3:36 am
  • Editorial Team
    Editorial Team added an answer 4) Yes, lock it. The other threads will just have… May 14, 2026 at 3:36 am

Related Questions

For my Django app I have Events, Ratings, and Users. Ratings are related to
In my django app, I handle login in the following manner. Users go to
I am getting ready to deploy my first Django application and am hitting a
I'm developing a Django app, and I'm trying to use Python's logging module for
I have a django app that uses MySQL as the database backend. It's been

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.