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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:25:05+00:00 2026-06-17T07:25:05+00:00

IN the Django docs they say this https://docs.djangoproject.com/en/dev/topics/auth/default/#user-objects from django.contrib.auth.decorators import login_required @login_required(login_url=’/accounts/login/’) def

  • 0

IN the Django docs they say this https://docs.djangoproject.com/en/dev/topics/auth/default/#user-objects

from django.contrib.auth.decorators import login_required

@login_required(login_url='/accounts/login/')
def my_view(request):

But how can i use login_required on class based view

@login_required
classMyCreateView(CreateView):

This gives error

'function' object has no attribute 'as_view'

  • 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-17T07:25:06+00:00Added an answer on June 17, 2026 at 7:25 am

    You can do that in many ways like

    https://docs.djangoproject.com/en/dev/topics/class-based-views/#decorating-class-based-views

    1. Either this
     urlpatterns = patterns('',
            (r'^about/', login_required(TemplateView.as_view(template_name="secret.html"))),
            (r'^vote/', permission_required('polls.can_vote')(VoteView.as_view())),
        )
    
    1. Or this
    class ProtectedView(TemplateView):
        template_name = 'secret.html'
    
        @method_decorator(login_required)
        def dispatch(self, *args, **kwargs):
            return super(ProtectedView, self).dispatch(*args, **kwargs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It's from Django's official doc: https://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships The models are like: class Person(models.Model): name =
Django stated in their docs that all query sets are automatically cached, https://docs.djangoproject.com/en/dev/topics/db/queries/#caching-and-querysets .
I try to use assignment_tag from django docs: https://docs.djangoproject.com/en/1.4/howto/custom-template-tags/#howto-custom-template-tags-simple-tags Test project: mysite/ manage.py polls/
A quickie, and hopefully an easy one. I'm following the docs at http://docs.djangoproject.com/en/dev/topics/auth/ to
Using django comments framework http://docs.djangoproject.com/en/dev/ref/contrib/comments/ Not sure is there option, to make all comments
Reading about Django, I saw this: http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#ref-contrib-admin - the fancy simple to use admin
I'm running Django 1.2 beta and trying out the new feature: message framework. http://docs.djangoproject.com/en/dev/ref/contrib/messages/
I've read the Django documentation here: http://docs.djangoproject.com/en/dev/ref/forms/validation/ I've also browsed a number of search
I'm using this one: https://github.com/pinax/django-notification/blob/master/docs/usage.txt So, I followed all the steps. from notification import
I have followed the tutorial (parts 1 and 2) on the Django site (https://docs.djangoproject.com/en/1.4/intro/tutorial01/)

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.