0

in my urls.py I need to invoke a generic CreateView that requires a success_url parameter. The "success" URL contains an identifier that I need to pass to the reverse() URL search function. I get this parameter from the URL of the CreateView. please see the code below. I need to grab the value of the <pk> parameter in the "create" url, and pass it on to the "success" url. how is this done?

thanks

konstantin

PS: using django trunk

...
url(r'^path/(?P<pk>\d+)/apply/$',
    generic.CreateView.as_view(form_class=MyForm,
                               success_url=reverse_lazy('success', args=[???<pk>???]),
                               template_name='create.html'), name='create'),
url(r'path/(?P<pk>\d+)/apply/success/$',
    generic.TemplateView.as_view(template_name='success.html'), name='success'),
...

1

1 Answer 1

2

This is explained in the documentation:

success_url may contain dictionary string formatting, which will be interpolated against the object's field attributes. For example, you could usesuccess_url="/polls/%(slug)s/" to redirect to a URL composed out of the slug field on a model.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.