I am beginner in django. I Rendered fields manually from modelform by using {{form.field_name}}.There are 5 fields in my model . how can i save field data by using class based view.
When Rendered fields by using {% form %} then i can save my form by using CreateView.like this
class StudentCreate(CreateView):
model = StudentDetails
fields = '__all__'
success_url = reverse_lazy('list-student')
but when i Rendered fields manually from modelform by using {{form.field_name}}.. i can't save it by using Createview.. Any idea about it? Why is this not working ? How can i save it?
Forms.py
class Student(forms.ModelForm):
class Meta:
model = StudentDetails
fields = "__all__"
Template code
{{form.name.label_tag}} {{form.name}}
You have to be very careful and specific when naming your custom fields. If you don't, Django will not recognize the form fields and ignore them.
If you want to see how you should do it, just render your {% form %}
and look in the source code. Then you have to use exactly same names for your custom fields.