Answer the question
In order to leave comments, you need to log in
Is it possible to create urlpatterns dynamically in django?
The problem is this: there is a service where users can create their own sites. Each site is accessible by a domain name like site1.app.com, site2.app.com, etc. Users can create arbitrary pages with arbitrary URLs on their sites.
I want to dynamically create a routing scheme in my application, depending on which subdomain the request came to. Those. roughly speaking, I need to understand which subdomain the request came to, pull out all the pages created for this subsite from the database and create urlpatterns according to these pages.
Is this even possible, or dig in the direction of one universal view-router?
Answer the question
In order to leave comments, you need to log in
It seems that in your case it is enough to create a url pattern like this:
urlpatterns = patterns('',
...
url(r'^pages/(.*)', page_dispatcer),
)
def page_dispatcher(request, path):
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question