R
R
Romua1d2016-11-04 14:02:59
Django
Romua1d, 2016-11-04 14:02:59

How to push a form into tamlate tags?

There is a form.
How to pass it to the url is clear. And how to transfer it to template tags?
After all, the form needs a URL where to send POST information.
Required for contact form

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VadimChin, 2016-11-04
@Romua1d

you can send it to the same view,
but this is a crutch, you don’t need to do this (forms must be in views)

@register.simple_tag(takes_context=True)
def my_form(ctx, ...):
    request = ctx['request']
    form = MyForm(request.POST or None, request.FILES or None)
    if form.is_valid(): 
        ...
    return render_to_string(tpl, {'form': form})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question