开发者

How to pass template variable to django wizard form

开发者 https://www.devze.com 2023-04-01 05:14 出处:网络
I have done a simple wizard form as following forms.py cla开发者_运维百科ss Posting_Wizard(FormWizard):

I have done a simple wizard form as following

forms.py

cla开发者_运维百科ss Posting_Wizard(FormWizard):

    def done(self, request, form_list):
        return HttpResponseRedirect(reverse('accounts-registration-wizard-done'))

    def get_template(self, step):
        return 'listing/post/wizard/wizard_%s.html' % step

and then created a view that renders the wizard above.

views.py

def post_wizard(request):
    contextz = {
        'dude' : 'text is appearing',
    }

    form = Posting_Wizard([SelectMainCategory_Form, ])

    return form(
        context=RequestContext(request , contextz),
        request=request
    )

the form is getting rendered successfully but I want to pas a context variable so i can use it in a specific step or any step. Any one has any idea how i can do that?

best wishes,


You can provide the attribute extra_context as a dictionary in your Posting_Wizard class or pass it in your url configuration.

See here for details: https://docs.djangoproject.com/en/1.3/ref/contrib/formtools/form-wizard/#creating-templates-for-the-forms

You could also override the render_template method on your FormWizard subclass to add custom context.

0

精彩评论

暂无评论...
验证码 换一张
取 消