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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:40:36+00:00 2026-05-27T22:40:36+00:00

I have a Django application which liberally uses django.contrib.auth.decorators.login_required() and also django.views.decorators.http.require_http_methods() . The

  • 0

I have a Django application which liberally uses django.contrib.auth.decorators.login_required() and also django.views.decorators.http.require_http_methods(). The former is a decorator which checks whether the current user is logged in, and redirects them (with code 302, IIRC) to the login page if not logged in. The latter is a decorator which examines the request method, and returns 405 (method not implemented) if the method isn’t in the passed-in list. So, as an example, a view function might look like:

@require_http_methods(["GET", "POST", "DELETE"])
@login_required
def my_view(request):
    ...

Here’s the problem: Many of these views do internal permission checks which return 403 (forbidden) if the user lacks sufficient permissions for the resource. According to my research, this is bad, because 403 needs to happen before examining whether the method is correct. However, without login_required(), I would have to open-code the user checks as well in my views.

Has anybody else experienced this? Is there a correct answer? I know it’s cheating, but is it unacceptable to check methods, then do the login redirect, then finally check user permissions, or do I need to restructure these views?

  • 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-27T22:40:37+00:00Added an answer on May 27, 2026 at 10:40 pm

    I’m not really sure about the ‘correctness’ of your order, but for any sort of complex view permission scheme I would highly recommend writing your own custom middleware to take care of view authentication / permissions. Rather than decorate every view with @login_required I always just take care of it in my own middleware.

    You can also write your own view decorator(s) (which may or may not take arguments) and get exactly the behavior you want for different views.

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

Sidebar

Related Questions

I am using the standard User model (django.contrib.auth) which comes with Django. I have
I have a django application xxx which does a number of things. I also
I have set up a Django application that uses images. I think I have
I have a Django application which sometimes needs to send some data through TCP
I have a Django application which edits a database table, which another application polls
I have a view my Django application which when invoked calls my backend. My
I've a django application, served via Twisted, which also serves ohter services (three sockets,
I have a Django application in which I need to implement a simple trending/ranking
I have a a django application which is being served from apache/mod_wsgi under www.mysite.com/mysite
I want to have RSS feeds in my Django application, which should be viewable

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.