Manual display of subfields MultiValueField

In my Django 1.7 application, I am trying to use the MultiValueField class to implement a password form element / password confirmation, i.e. two separate password fields requiring user input and then confirmation of a new password. I already got this working with two separate fields and the clean() method in my form, but the β€œsingle” MultiValueField seems to be the best way to uphold the DRY principle, especially since I will need to duplicate this not only in my form user registration, but also when users want to change their passwords.

However, my front-end is quite specific, but not the least significant bit, like Django default form output, so I manually render my form fields . This works great - until I get to MultiValueField. For each form field, my HTML looks like this:

 <div class="row collapse"> <div class="small-2 columns"> <span class="prefix"><i class="fi-mail"></i></span> </div> <div class="small-10 columns {% if form.email.errors %}error{% endif %}"> {{ form.email }} {% if form.email.errors %}<small class="error">{{ form.email.errors }}</small>{% endif %} </div> </div> 

I need to do a similar formatting for each of the subfields of form.password , but none of what I tried provided me with a rendering subfield; the closest I came is {{ form.fields.password.fields.0 }} in my template, which gives me output like <app.fields.PassField object at 0x7fb619821ef0> , however this is clearly not a displayed form field.

Is there something simple and obvious that I am missing, or is that what I am trying to do is simply impossible in Django?

+6
source share
1 answer

Render code is just one part of Django's MultiWidget that fits your problem, as farthVader suggests.

0
source

Source: https://habr.com/ru/post/979374/


All Articles