Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango cross-site reverse URLs
    primarykey
    data
    text
    <p>Probably simple question and I'm just missing something, but I'm stuck out of ideas.</p> <p>I have Django project serving several sites with distinct <code>sessions.py</code> and completely different <code>ROOT_URLCONF</code>s. One site handles user registration, authentication and profile settings, other site (on another domain) acts as file manager and so on. Sites are sharing the same DB, media and templates. All sites are sharing the same userbase, implementing sort of transparent single-sign-on/single-sign-off mechanism. It is just like one big site, spanning across several domains.</p> <p>The problem is, I have a lot of <code>{% url %}</code> tags in my templates, and they don't work when template's used on other sites. And I'd like to avoid hardcoding URLs as much as possible.</p> <p>For example, on site A (a.example.org) I have an</p> <pre><code>url('^users/$', 'example.accounts.list_users', name='list_users'), </code></pre> <p>entry in A's URLconf. Then, in some <code>global_menu.html</code> template I have <code>{% url list_users %}</code> and obviously it works perfectly, resulting in "<code>/users/</code>".</p> <p>Now, there's site B (b.example.org), sharing a lot of internals with A. To have common look-and-feel I want to use the same <code>global_menu.html</code> on site B and want <code>{% url list_users %}</code> to output "<code>http://a.example.org/users/</code>". What's the best way I can achieve this?</p> <p>Currently, I'm using separate <code>global_menu.html</code> for each site, but this violates DRY principle, and not really convenient. And, yes, I'm using Django's <code>contrib.sites</code> framework with distinct <code>SITE_ID</code>s defined in <code>settings.py</code> for each site, but not yet actually using it anywhere else.</p> <p><strong>Update</strong>: Currently I'm thinking of reimplementing <code>url</code> tag or monkey-patching <code>reverse()</code>, to call the original one, and on exceptions perform additional look up in some "foreign URI list". If there already exists anything like this — I'd be happy to hear.</p> <p>Thank you in advance for answers!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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