0

I need to achieve the following :

<input type="text" name="montantHT{{ vente.id}}" value="{{ vente.montantHT }}" />

However, I dont want to work with normale html forms, but with Django forms, so if I have form like this :

class UpdateFacture(forms.Form):
    montantHT=forms.Charfield()

and of course called in my view and passed on context as form, so how can I put it on my template so I can get the same html I mentionned at first, with name="montantHT{{ vente.id}}" value="{{ vente.montantHT }}"

Any Help please I've tried multipule syntaxes but cant get it as I want. Thank You

Elroum
  • 327
  • 1
  • 3
  • 18

2 Answers2

1

You can completely render Django form fields manually, whilst still making use of the backend form functionality.

See this section of the docs information regarding manual rendering - https://docs.djangoproject.com/en/2.0/topics/forms/#rendering-fields-manually

HOWEVER, be careful as the HTML you have proposed will not work since the form field name you have in your HTML does not match the field name in the Django form and so will raise an error.

Without more context of what you are trying to do it is hard to propose a solution to this problem.

Grant Anderson
  • 322
  • 1
  • 8
0

Maybe you could try setting form widget attributes, like the docs and this post show

Ralf
  • 16,086
  • 4
  • 44
  • 68