fakeMake
fakeMake

Reputation: 778

Use request.session as the success_url in django

I have a CBV that I need to pass a request.session variable to as the success_url. I have not been able to implement this. May somebody help, please.

class UpdateTeacherIssueView(LoginRequiredMixin,UpdateView):       
    model = TeacherIssue
    form_class = UpdateTeacherIssueForm
    template_name = 'crud_forms/edit_teacher_issue.html'
    success_url =reverse_lazy('all', path = selected_item>) 

In function based views it would be, selected_item = request.session.get('item') How is the same possible in CBV?

Upvotes: 0

Views: 201

Answers (1)

Aniket Pawar
Aniket Pawar

Reputation: 56

write getter for success URL like

def get_success_url(self):
   return '/<your url>/'+self.request.session.get('item')

it will overwrite success URL

Upvotes: 1

Related Questions