How to Display the Date in Spanish in Django



Python


In this article, we show how to display the date in Spanish in Django.

Django is very adaptable and has support for many other languages besides English, such as Spanish.

If you are creating a spanish site or a portion of your website in Spanish, we can do this easily in Django.

In order to do this, we first load in i18n, which allows for translations within templates.

So let's say that we have a variable named document.pub_date.

We can translate this document into Spanish with the following code shown below.



So we load in i18n, which gives us the language attribute.

The spanish language has a code of 'es'.

We output the date by using the date template filter.

We then close out the translation by ending the language attribute with, {% endlanguage %}

Now we have the date in Spanish.

If you want the time as well, then you would take out the date template filter tag.

And this is how to display the date in Spanish in Django.


Related Resources

How to Randomly Select From or Shuffle a List in Python



HTML Comment Box is loading comments...