2π
Add SUB_SITE
to your settings.py:
# settings.py
SUB_SITE = "/test/"
And then in settings.py
:
urlpatterns = patterns('',
(r'^%s/' % settings.SUB_SITE, include('urls_subsite')),
)
More on it:
Another option is to use this peace of code in urls.py
:
if settings.URL_PREFIX:
prefixed_urlpattern = []
for pat in urlpatterns:
pat.regex = re.compile(r"^%s/%s" % (settings.URL_PREFIX[1:], pat.regex.pattern[1:]))
prefixed_urlpattern.append(pat)
urlpatterns = prefixed_urlpattern
More on it:
But I personly think that the first solution is much better.
1π
I donβt believe you should run a βsubβ site within the same process by rewriting the patterns like the answer by @IgorChubin suggests, that should be an app.
If you really want to have two sites running on the same domain, even if they both use Django, run separate (virtual)servers.
If you really must do this, use the server config to rewrite a specific url and run separate processes
IMO, the obvious options would be to:
- create a prefixed app within the project, or;
- create a subdomain
Then possibly use the Django sites framework to merge administrative tasks for the latter option.
- [Django]-Django template variable in style tag
- [Django]-Dynamically combine Q() β OR objects
- [Django]-Django: Issues with extending User model
0π
A simple answer I use is,
from django.http import HttpResponse, HttpResponseRedirect
# hook for testing in local server, compatible with server deployment
def redirect_to_xkcd( request, everythingelse ):
return HttpResponseRedirect( "/"+everythingelse, request )
and add this line to the urlpatterns
url(r'test/(?P<everythingelse>.+)', redirect_to_xkcd ),
- [Django]-Django: save multiple object signal once
- [Django]-Reverse for 'edit_user' with arguments '(2L,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []
- [Django]-How to adding middleware to Appengine's webapp framework?