margusholland
margusholland

Reputation: 3348

URL template tag without locale in Django 1.4

I added locale specific URL-s to my Django app with i18n_patterns and it’s all working nicely, but in some cases I need to have an url pointing to a view without the locale information.

My current setup works so that english pages don’t have a locale in the path, e.g: www.foobar.com, but all other as www.foobar.com/et/ etc. This works nicely. Now, every user has a "public profile" page in www.foobar.com/u/123 etc.

If I just do a {% url user_profile_page %} in a template, I always get the locale also in the URL, but I’d like for it always show the non-locale version, because I want the public profiles to have a non-locale URL (and the fact that if someone is using a different language and then it redirects to the locale based URL, is fine).

There’s nothing the Django documentation that suggest that the {% url %} template tag is able to do this, but is there something?

Upvotes: 1

Views: 181

Answers (1)

Joonathan
Joonathan

Reputation: 144

In template code you should be able to use the {% language %} tag in the following manner to specify language for url reversing:

{% language en %}
<a href="{% url user_profile_page %}">User 1</a>
{% endlanguage %}

Specifying the english language code in this case should result in url without prefix.

Upvotes: 2

Related Questions