DateField localization in Templates

I am using a date input in my form template. It accepts a value in form of A DOMString representing a date in YYYY-MM-DD format, or empty but Django gives me a value in due to localization.

Also I am using widget_teaks in my form view to add some Attributes:

{% if field|field_type == 'datefield' %}
    {% render_field field|append_attr:"class:form-control dateField " type="date"  %}
{% else %}

I tried to fix it in the template using jQuery but it returns just an empty string for the value:

    var date = $(".dateField").val();

So I can’t just update the value accordingly. I tried to unlocalize the whole template but still the date is formated in

The relevant part of the settings:


USE_I18N = True

USE_L10N = True

USE_TZ = True

and the relevant Field in the Model:

naechste = models.DateField(verbose_name="nächste Prüfung")

and the Form itself:

class Massnahmen_Form(forms.ModelForm):
    class Meta:
        model = Massnahmen
        exclude = ["version", "latest_version"]

Can you tell me what I am doing wrong?

Clarify please. When you say “Django is giving me a value as”, are you saying that existing data for that field is showing up in that format? Or are you saying that when the form is submitted, that’s how you’re seeing the date in your view?

Hi Ken,

It shows up in my UpdateView From. In the Template Field the value of value arg in the html input is in the format.

Have you tried setting the DATE_FORMAT and DATE_INPUT_FORMATS settings?

(I haven’t tried this, this is just what I managed to find in the docs.)

(Note: Both point out that they are overridden if USE_L10N is True, so you’d need to make sure that localize is off for that section of your template.)


1 Like

Setting L10N to False worked, Tanks Ken!