This is a question for folks experienced with pyth...
# random
l
This is a question for folks experienced with python & Django. I am just picking up python & Django properly (a little late to the party). Anyways, I have my models and all done. I need to create Django forms for these models. All the tutorials that I have come across on Youtube & Udemy, create the form using the
Copy code
{{ forms.as_p }} or {{ forms.as_table }}
I need to create the forms in HTML by hand as the structure of the page is a little more complex than what these provide. I know that I can do this (create a HTML form by hand) and then pluck the values in the
view.py
using:
Copy code
value = request.form["name"]
My question is whether this is the recommended way to do this? I would have hoped that instead of creating the entire form in one go using:
{{ <http://forms.as|forms.as>_p }}
, there would be an option to hand-craft individual form elements but with the Django helpers. After which, I would be able to use the internal Django form helpers to read the values and validate the form. From my ASP.Net days, I remember we could do something like:
Copy code
<input type='text' name='forms.student_name.name' value='forms.student_name.value' />
Does Django offer something like this? Any pointer to a tutorial or site I can look at would be appreciated. Thanks!
b
Copy code
{% for field in form %}
    {{ field }}
{% endfor %
you can now access field attributes and design them as you like
👍 4
🙏 1
l
Thanks @brief-memory-68420 Also found more info here: https://docs.djangoproject.com/en/4.0/topics/forms/ (towards the bottom of the docs).
👍 1