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 8578567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:25:13+00:00 2026-06-11T20:25:13+00:00

Lets just suppose that we have following url: example.com/users/1 if user with ID=1 opens

  • 0

Lets just suppose that we have following url:

example.com/users/1

if user with ID=1 opens it, user receive info about his account, but if user switch 1 with 2, then he can view other user details as well, and we of course do not want that, so I have following solutions:

1) just pass currently logged in user id threw request.user.id inside a template

2) add permission, but I did not find type of permissions that would allow me to do that. Of course I could create dozens of permissions each for each user, but of course that is very nasty way.

Any other ideas how to cope with that in Django?

  • 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-06-11T20:25:14+00:00Added an answer on June 11, 2026 at 8:25 pm

    You can either fill context with the request which makes sure the user will never see another user’s data, e.g. (using CBVs):

    class AccountView(TemplateView):
        """
        Generic account view
        """
        template_name = "users/account.html"
    
        def get_context_data(self, **kwargs):
            context = super(AccountView, self).get_context_data(**kwargs)
            context['user'] = User.objects.get(id=self.request.user.id) 
            return context
    
        @method_decorator(login_required(login_url=reverse('login')))
        def dispatch(self, *args, **kwargs):
            return super(AccountView, self).dispatch(*args, **kwargs)
    

    Another approach, to make sure ‘fake’ urls render 404’s is to write an owner_required decorator, e.g.:

    def owner_required(function):
        @wraps(function)
        def decorator(*args, **kwargs):
            request = args[1]
            user = get_object_or_404(User, username=request.user.username)
            if user.is_authenticated() and user.username == kwargs.get('slug'):
                return function(*args, **kwargs)
            raise Http404
        return decorator
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets just say that I have three textboxes: TextBox1, TextBox2, TextBox3. Normally if I
just a question that needs a quick answer, I have a Action, lets say,
Let's suppose I have the following url: /valid/django/app/path/?foo=bar&spam=eggs I can simulate a request to
Lets suppose I have a scenario with the following model: An Animal table which
Let's suppose that I have the following table: employee (id, name, surname, salary); The
Lets suppose that I have simple html markup: <div> <input type=text/> </div> when I
There's a nice plugin for Frog CMS that lets you just type in yourpicture.120x120.jpg
Lets say I have hierarchy like this (This is just a test program. Please
Lets say I have the string: MyNamespace.SubNameSpace.MyClassName How do I extract just everything after
Isn't having String enough? Just as an example, why can String class lets you

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.