old-willow
old-willow

Reputation: 111

Django accessing context data inside get_success_url

In my get_context_data method I create context variable only if certain conditions are met.

I want my form to be able to redirect different urls regarding that context variable is created or not.

How to access context['something'] in get_success_url method? Or is it possible?

Upvotes: 0

Views: 1079

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599450

get_context_data won't even be called if the form is valid, because a redirect needs no context. You should put that calculation somewhere else, perhaps into a separate method which could be called both from get_context_data and form_valid.

Upvotes: 1

Related Questions