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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:47:10+00:00 2026-06-13T08:47:10+00:00

In my app, I have two different login pages according the user that need

  • 0

In my app, I have two different login pages according the user that need to log in. So I cannot use settings.LOGIN_URL.

I am also using class-based views, so I have to use method_decorator(login_required).

At this moment, I have a class decorator (I am using Python 2.7) that does pretty much all what I want, except for the login_url. Code is a snippet and hand-typed, so it may have typo.

login_required_m = method_decorator(login_required)
def requires_role1(view):
  def requires_m(func):
    @wraps(func)
    def wrapper(self, request, *args, **kwargs):
      # I need to process request.user
      if (not ok):
        return redirect(urlresolvers.reverse('some_name'))
      else:
        f = login_required_m(func)
        return f(self, request, *args, **kwargs)
    return wrapper
  view.get = requires_m(view.get)
  view.post = requires_m(view.post)
  return view

The line that really concerns me is:

`f = login_required_m(func)`

On a function based view, I would have been able to define:

`f = login_required(func, login_url='some_reverse_path')`

but with method_decorator(login_required), I am no longer able to pass login_url as a parameter. Remember, I need to be able to do so because I have two different login urls. They provide totally different sets of usernames and passwords (same username can be in both set with different passwords and associated to different people).

Any help in what I should do to accomplish this would be much appreciated.

EDIT

Accorded to accepted answer, here is the solution I adopted:

def login_required_partial(func):
  return partial(login_required, login_url=urlresolvers.reverse('role1_login'))

login_required_m = method_decorator(login_required_partial)

and left the rest of the code unchanged. And it all seems to work well when there are no parameters passed by ulr(r'path/(?P<param1>.*)', CBV.as_view(), name='path_name').

Anyone with a good way to fix this now?

  • 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-13T08:47:11+00:00Added an answer on June 13, 2026 at 8:47 am

    You can decorate the CBV view function:

    # urls.py
    
    from myproj.myapp import views
    
    myview = login_required(views.MyView.as_view(), login_url=None)
    
    urlpatterns = patterns('',
        url('^$', myview),
    )
    

    Or you can create some sort of a mixin:

    from django.contrib.auth.decorators import login_required
    from functools import partial
    
    class LoginRequiredMixin(object):
        """
        A mixin used for views that can only be accessed by authenticated users.
        """
    
        login_url = None
    
        def _login_required(self):
            return partial(login_required, login_url=self.login_url)
    
        def dispatch(self, request, *args, **kwargs):
            def inner(*args, **kwargs):
                klass = LoginRequiredMixin
                return super(klass, self).dispatch(*args, **kwargs)
    
            return partial(inner, login_url=self.login_url)(request, *args, **kwargs)
    

    And use it like so:

     # View class
     class MyView(LoginRequiredMixin, View):
         login_url = lazy_reverse('foo')
    
         pass
    
     # Or a view function in urls.py
     myview = views.MyView.as_view(login_url=reverse('foo'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an Android app and I need to have two different themes for
I have a clojure/ring project that has two distinct app/handlers running on different ports
I have two tabs on my app that handle different flows. For each tab
I have a two different ways of representing data in my app: via UITableView
I have an App that I want to have two version in the App
I am developing a web app that will have two parts running on two
I have two windows in my WPF app: a login window and an options
Lets say that I have two different types of RelativeLayouts. That is to say
In my rails app, I have two layouts/controllers for different actions. Eseentially, I match
I need three different sections in my app: a login screen, a main screen,

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.