I searched for an answer for a while without success. I basically want to get the name of the form field with the prefix enabled. Does anyone know how to do this?
Example:
Let's say I create a form in views.py and include a prefix like this:
myform = SomeForm(prefix="prefix")
and then pass it to my template. If I then access the form field inside the template directly, I {{myform.username}} get something like this (note that the prefix has been enabled):
<select id="id_prefix-username" name="prefix-username"> ...
If I would like to manually create a form tag and just insert the name, then I will not get a prefix with it:
<input name="{{ myform.username.name }}">
will generate:
<input name="username">
Notice how the prefix is now missing. Now I can do it this way to achieve the same result:
<input name="{{ myform.prefix }}-{{ myform.username.name }}">
But should there be an inline way to do this?
Anton source share