Consider these two ways of defining the success_url. The first is commented out,
the second is the function:
class NewJobCBV(LoginRequiredMixin, CreateView):
template_name="company/job.html"
form_class = newJobForm
# success_url = reverse_lazy('newJob')
def get_success_url(self, **kwargs):
return reverse("newJob")
@CoffeeBasedLifeform : you are right, class attributes are evaluated on import, I checked after reading your answer. So,
- If we are using
success_urlwe have to usereverse_lazy(). - If we are reversing inside a function we can use
reverse().
Now it is crystal clear.
Thanks CoffeeBasedLifeform 🙂