1👍
✅
Ok, I found the solution… It’s not very clever, but it works:
In my urls.py, I wrote the rule, that accepts all requests and points them to page_dispatcher view:
urlpatterns = patterns('',
url(r'^$', 'app.account.site.views.page_dispatcher'),
url(r'^(?P<path>.+)$', 'app.account.site.views.page_dispatcher'),
)
After that, in my views.py I’ve created the dynamic url configuration and use the resolve() function to resolve view that corresponds to requested path:
class DynamicURLConf(object):
urlpatterns = None
def __init__(self, pages):
self.urlpatterns = patterns('',
url(r'^$', 'app.account.site.views.test'),
url(r'^test/$', 'app.account.site.views.test'),
)
def page_dispatcher(request, path=None):
if path is None:
# Here will be a return a homepage view
return
func, args, kwargs = resolve(urlparse("/" + path.strip("/") + "/")[2], DynamicURLConf(pages=None))
kwargs['request'] = request
return func(*args, **kwargs)
def test(request):
return HttpResponse("I am test")
0👍
It is easy to do so!
you should konw that when deploy a website with appache2 + mod_wsgi
wsgi.py
you will find settings.py
and in settings.py
you find corresponding urls.py
so just use two or more settings.py
and urls.py
in project
and change your apache configration file
john.app.com -> john.conf -> john.wsgi.py -> john.settings.py -> john.urls.py
see here:http://www.besttome.com/html/run_multiple_websites_one_django_project.html
Source:stackexchange.com