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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:57:51+00:00 2026-05-23T03:57:51+00:00

I have some sections on my web site where only logged in users can

  • 0

I have some sections on my web site where only logged in users can see their resources.

I also want to make absolutely sure that only that authorized user can modify and delete his/her records. What’s the best practice and more secure way of accomplishing this in Django?

Real examples would be truly appreciated.

  • 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-23T03:57:52+00:00Added an answer on May 23, 2026 at 3:57 am

    For my project, I created a Decorator that checked if the right user was logged in:

    #decorator.py
    from django.http import HttpResponseRedirect
    from django.core.urlresolvers import reverse
    
    def same_user_required(func):
        def wrapper(request, user):
            if not request.user.is_authenticated():
                return HttpResponseRedirect(reverse('login-view'))
            if not user == request.user.username:
                return HttpResponseRedirect(reverse('login-view'))
            return func(request, user)
        return wrapper
    

    You then add it to any views that need checking:

    #view_profile.py
    from apps.utilities.decorators import same_user_required
    
    @same_user_required
    def edit_profile(request, user):
    

    Note that my URL contains the username /profile/edit/<username>, which is where the parameter comes from, in the edit_profile view.

    Another way is to use the Django built-in decorator, user_passes_test (see Django Book Chap 14 for an example of its usage. You then just have to write the test, not the decorator boilerplate code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I have a table view with some sections which have their own headers
I have following statement for query articles from some sections Article.all(:joins => :sections, :conditions
We have been doing some research into physically isolating the secure and non-secure sections
I have 3 tables, - Section table that defines some general item sections. -
I have a website which in a section gives users access to some documents.
I have an ASP.net Web Site Project (.net 3.5). Currently all of the non-code
I only began learning about web development 3 weeks ago and have grasped html,
A client has sent me their web site and I got it to work
I'm working on a web site which contains sections that need to be secured
I have some dropdown menus that are display:none and only show upon click (using

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.