How to link the Forms created in Django with the forms already created in the HTML template?

2

I started to see about forms in Django, except that I had already created the forms with all the required% as required in my project's templates . Is there a way I can bind each inputs to a form already created in the template so that it does not create another forms with form ? p>     

asked by anonymous 13.05.2014 / 18:44

1 answer

3

As explained in this section of the documentation , you do not need use the automatic form generation method ( {{ form.as_p }} ) if you do not want to. It is enough that your template has the correct input fields (with name s appropriate to each field).

One way to find out what format is expected by a specific Form is - in the shell for example - call the as_p method and see what its output is:

>>> f = ContactForm(auto_id=True)
>>> print(f.as_p())
<p><label for="subject">Subject:</label> <input id="subject" type="text" name="subject" maxlength="100" /></p>
<p><label for="message">Message:</label> <input type="text" name="message" id="message" /></p>
<p><label for="sender">Sender:</label> <input type="email" name="sender" id="sender" /></p>
<p><label for="cc_myself">Cc myself:</label> <input type="checkbox" name="cc_myself" id="cc_myself" /></p>

Font

From here you can check if your manually created template conforms to what is expected by Form , and if it is you can use it without problems.

    
13.05.2014 / 19:24