1

I written this logic in my views.py, and I used class based views, Detail view:

@login_required
class profileView(DetailView):
    model = profile
    template_name = "users/profile.html"

and in urls.py file I've written this:

from django.urls import path,include
from . import views
from .views import profileView

urlpatterns = [
    path('register/',views.register,name="register"),
    path('login/',views.login_user,name="login_user"),
    path('profile/',profileView.as_view(),name="profile_view"),
]

the django version that I'm using is 3.1 and python version is 3.8.

I hope that someone has an answer to my question.

0

1 Answer 1

1

You can not make use of @login_required for a class-based view, since that returns a function. You use the LoginRequiredMixin [Django-doc]:

from django.contrib.auth.mixins import LoginRequiredMixin

class profileView(LoginRequiredMixin, DetailView):
    model = profile
    template_name = 'users/profile.html'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.