Reputation: 2309
class EventDeleteView(generic.FormView):
form_class = EventDeleteForm
template_name = 'event/event_delete.html'
def __init__(self, **kwargs):
super().__init__(**kwargs)
---> self.event = Event.objects.get(pk=self.kwargs['pk'])
def get_form_kwargs(self):
kwargs = super().get_form_kwargs()
---> kwargs['pk'] = self.kwargs['pk']
What I do not understand is why self.kwargs['pk']
in the get_form_kwargs(self)
method works and why it does not work in the constructor.
I get this error: 'EventDeleteView' object has no attribute 'kwargs'
Upvotes: 1
Views: 58
Reputation: 2305
It’s because self.kwargs
is set in the view function returned from .as_view
and not in the base class constructor.
Upvotes: 1