'Even though its a class why is AttributeError: 'function' object has no attribute 'as_view'
even though its a calss based func why is this attribute error popping up when i use login_required
error Message
path('active/<int:pk>', UpdateActiveStatus.as_view(), name="activeStatus"),
AttributeError: 'function' object has no attribute 'as_view'
views.py
@login_required(login_url='/admin/')
class UpdateActiveStatus(UpdateView):
model = Timeline
form_class = UpdateActiveStatus
template_name = 'timeline.html'
success_url = reverse_lazy('timeline')
Solution 1:[1]
I think the issue is generated for the decorator. Just change it like ->
@method_decorator(login_required, name='dispatch')
class UpdateActiveStatus(UpdateView):
model = FutsalTimeline
form_class = UpdateActiveStatus
template_name = 'timeline.html'
success_url = reverse_lazy('timeline')
You can find the doc here
But you should use the Mixin classes. With Mixin class It will look like
from django.contrib.auth.mixins import LoginRequiredMixin class UpdateActiveStatus(LoginRequiredMixin, UpdateView): model = FutsalTimeline form_class = UpdateActiveStatus template_name = 'timeline.html' success_url = reverse_lazy('timeline')
You can find the doc here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Almabud |
