Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I set urlpatterns based on domain name or TLD, in Django?
    text
    copied!<p>How do I set urlpatterns based on domain name or TLD, in Django?</p> <p>For some links, Amazon shows url in native language based on its website tld.</p> <p><a href="http://www.amazon.de/b%C3%BCcher-buch-literatur/" rel="nofollow noreferrer">http://www.amazon.de/bücher-buch-literatur/</a> ( de : books => bücher )</p> <p><a href="http://www.amazon.fr/Nouveaut%C3%A9s-para%C3%AEtre-Livres/" rel="nofollow noreferrer">http://www.amazon.fr/Nouveautés-paraître-Livres/</a> ( fr : books => Livres )</p> <p><a href="http://www.amazon.co.jp/%E5%92%8C%E6%9B%B8-%E3%83%A6%E3%83%BC%E3%82%BA%E3%83%89%E3%83%96%E3%83%83-%E8%8B%B1%E8%AA%9E%E5%AD%A6%E7%BF%92/" rel="nofollow noreferrer">http://www.amazon.co.jp/和書-ユーズドブッ-英語学習/</a> ( jp : books => 和書 )</p> <p>( the links are incomplete and just show as samples. )</p> <p>Is it possible to get host name in urls.py? (request object is not available in urls.py) or maybe in process_request of middleware and use it in urls.py(how???)</p> <p>Any alternate suggestions how to achive this? </p> <pre><code>#---------- pseudocode ---------- website_tld = get_host(request).split(".")[-1] #.fr French : Books : Livres #.de German : Books : Bücher if website_tld == "fr": lang_word = "Livres" elif website_tld == "de": lang_word = "Bücher" else: lang_word = "books" urlpatterns = patterns('', url(r'^%s/$' % lang_word,books_view, name="books"), ) </code></pre> <p>The url pattern needs to be built based on tld and later in the template, <code>&lt;a href="{% url books %}" &gt;{% trans "books" %}&lt;/a&gt;</code> to render html as <code>&lt;a href="Bücher"&gt;Bücher&lt;/a&gt;</code> or <code>&lt;a href="Livres"&gt;Livres&lt;/a&gt;</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload