[Answered ]-Implementing a site prefix across all apps

2👍

Design the URLs for myapp to be standalone (such that its URLs can be ‘included’ in the URLs of another project).

urlpatterns = patterns ('',
    (r'^$', 'myapp.views.index'),
    (r'^view/$', 'myapp.views.view'),
    ...
)

Notice that you’re not putting ‘myapp’ in your URLs at this point, but simply have a basic URL scheme that can be pointed wherever you want at deployment time.

Then, create a separate URLconf module for each target deployment (e.g., test vs. production) and use the django.conf.urls.defaults.include function to wire up the URLs to whatever arbitrarily deep base URL you want:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^PREFIX/myapp/', include('myapp.urls')),
    (r'^PREFIX/myapp2/', include('myapp2.urls')),
    (r'^PREFIX/myapp3/', include('myapp3.urls')),    
)

Point your deployment settings.py to use this URLconf module instead of pointing directly at the URL module for myapp.

Because my test environment looks quite different from my production environment, I like to have a separate settings module for each target deployment.

0👍

if your prefix is in the domain name, why dont you use root-relative urls ?

i always use this kind of urls which is very handy

<a href="/myapp/view">blex</a>
<img src="/static/img/blex.png"/>

hope this helps.

👤jujule

Leave a comment