1๐
โ
You can not use the @login_required
decorator [Django-doc]: this decorator returns a function, but even using the function will not work: the decorator simply can not handle a class.
For class-based views, you use the LoginRequiredMixin
[Django-doc]:
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')
login_url = '/admin/'
0๐
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
๐คAlmabud
- [Answered ]-Django โ how to pass object to ModelForm via UpdateView?
- [Answered ]-Can i use templatetags inside inclusion tags?
- [Answered ]-Override Django Admin Save Model
- [Answered ]-Django filter JSONField when key is a number
Source:stackexchange.com