Forms with Same View and Couple of Designs

I have a form which will use in many pages and could be use same form view.

A form view with many functions and properties.

Although their form fields and features are same, they have 3 different designs.

I want to create 3 different base form template and distribute them to the whole project using same view.

Is it possible using context processors proper choice for this purpose?

or how can I do this in a proper way?

Thanks in advance.

While I believe I understand what you’re saying here, unfortunately your description is also somewhat vague, making it difficult to offer any precise suggestions.

In the most fundamental sense, you can create any number of templates, and render the same form in those templates. There’s no direct connection between a template and a form. It’s the view that creates the instance of a form and passes it to the template being rendered via the context.

Beyond that, I’m uncertain as to what you’re really trying to achieve here.

@KenWhitesell, Thank you for interest.

Let me try to explain my problem more clearly,

Same form, Same to be done when the form is valid. (send form information by e-mail, get client IP, check Captcha etc.)

How can I avoid adding them over and over for every template the form is on?


What’s on my mind is,

main-form.html
multi-step-form.html

creating them and including them on all required pages.
I want these generalized form structures to work on the templates I want.

For example, I’ll distribute this form templates to index.html, contact -branches.html, department-list.html, department-detail.html and much more.

Ok, that’s clearer now, thanks.

Does the include tag do what you’re looking for, or is there some other aspect of this that I’m missing? (The with parameter allows you to pass information into the template to allow the included template to be customized from information in the enclosing context.)

Let’s say we are creating a class based form view.
Let the template name be main-form.html.

Will it work wherever I include it without other requirement?

Other template doesn’t have a context the form.

I thought I needed to use context processors or similar to use globally.

Still not sure I’m following you here. How can you render a form without passing it in through the context (directly or indirectly)?

If you’re using a CBV that inherits from FormView, the CBV calls get_form in get_context_data. This means that your template’s context is going to have the form available to it - it’s one of the functions performed by the CBV - you don’t need to do anything here. You can include your form’s template and pass it the form value from the context.

Because of I’m not good at terminology, I can not express it correctly.

Let me do a draft based on my thoughts and what you said.

If I’m not successful, we can communicate easily over code pieces.

Thanks.

1 Like