Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

300
Vistas
Django 1.10 - Form fields ignore attributes when rendered as hidden

I have declared form, which contains DateInput. DateInput has specified format attribute. This will format field's date value. At the same time, the form will expect the same format upon validation.

My Form:

class CoolForm(forms.ModelForm):

    class Meta:
        model = Event
        fields = ['day', 'time_from', 'time_to', 'type'] 
        widgets = {
            'day': forms.DateInput(format=('%d--%m--%Y'))
        }

Template:

{{ field.as_hidden }} <!-- is rendered with wrong format: -->

<input id="id_day" name="day" type="hidden" value="2017-04-30"> 


{{ field }} <!-- is rendered with correct format: -->

<input id="id_day" name="day" type="text" value="30--04--2017">

Problem:

In template when I print form using field.as_hidden, format remains unaffected from form setting. It even ignores attr attribute. How can I render field as hidden, while keeping its specified date format?

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda