Note that there are some explanatory texts on larger screens.

plurals
  1. POmultiple django projects at same url
    primarykey
    data
    text
    <p>I would like to have multiple django projects living at the same root url like this:</p> <pre><code>example.com/ # controlled by home django project example.com/project-2 # controlled by a separate django project example.com/project-3 # controlled by yet another django project </code></pre> <p>I am already redefining the LOGIN_REDIRECT_URL, etc. as <a href="https://stackoverflow.com/questions/3232349/multiple-instances-of-django-on-a-single-domain/3240190#3240190">suggested by this excellent answer</a>, but I have discovered another hurdle. I am actually using the same apps in the projects that live at example.com/project-2 and example.com/project-3, which causes some non-trivial problems for linking to content inside of a django project that have thus far been solved with seemingly hacky solutions.</p> <p>For example, you can never refer to '/' in any template in either example.com/project-2 or example.com/project-3 to return to the root of the django project hosted at either of these URLs --- this will link to the home django project at example.com. To get around this, I have made a context processor that correctly prepends the root url of the project based on a custom settings.py variable SCRIPT_NAME: '' (for example.com), '/project-2' (for example.com/project-2), or '/project-3' (for example.com/project-3). This is all fine and good except that you need to do the same thing in the get_absolute_url functions. Before I knew it, I had just turned a bunch of code that was very reusable (by people other than myself) into code that was not reusable at all. </p> <p>Is there a way to accomplish the same effect without having to prepend absolute URLs with the SCRIPT_NAME? Perhaps something clever with apache or mod_wsgi configuration? I am at a loss and hoping someone can help...</p> <p><strong>EDIT:</strong> </p> <p>My apache configuration for example.com looks like this:</p> <pre><code># redirect un-'/'-terminated urls to the '/'-terminated root urls RewriteEngine On RewriteRule /project-2$ /project-2/ [R=302,L] RewriteRule /project-3$ /project-3/ [R=302,L] # mod wsgi setup WSGIScriptAlias /project-2 /srv/project2/project-2.wsgi WSGIScriptAlias /project-3 /srv/project3/project-3.wsgi WSGIScriptAlias / /srv/project1/project-1.wsgi </code></pre>
    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