Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django template error - only option for 'trans' is 'noop'

Tags:

django

This is regarding Django tutorial - Part 2 http://docs.djangoproject.com/en/dev/intro/tutorial02/

In the section to change the template for admin page, I tried to change this section in the base_site.html page.

{% trans 'Django's administration' %}

When I add the apostrophe and s, I ge the error that - TemplateSyntaxError at /admin/ only option for 'trans' is 'noop'

Why is it so? I thought I should be able to change the site's name. I tried using double quotes and escape sequence also, but it did not work.

like image 902
Sumod Avatar asked Feb 25 '23 17:02

Sumod


2 Answers

I tried using double quotes and escape sequence also, but it did not work.

That is definitely the problem. That is the only problem that the error message specifies!

Are you positive there are no other places where you've done that?

It should be:

{% trans "Django's administration" %}

That error messages only exists for the tag "trans" and appears if there is any other argument in the tag that is not noop.

like image 141
Yuji 'Tomita' Tomita Avatar answered Feb 27 '23 07:02

Yuji 'Tomita' Tomita


The problem is the second single-quote:

{% trans 'Django's administration' %}

Django is treating everything after it as an argument. As the only argument it accepts is noop, this is causing an error.

One way to get around it is to do as Yuji 'Tomita' Tomita suggested, and enclose your translation string in double-quotes.

Another way is to use the blocktrans tag:

{% blocktrans %}
Django's administration
{% endblocktrans %}

As you're not using quotes to denote text which needs to be translated, this won't run into the same issue as the trans tag.

like image 40
Andrew Calder Avatar answered Feb 27 '23 06:02

Andrew Calder