John Mee
John Mee

Reputation: 52323

Is it possible to make URLs conditional with django?

I'm using the middleware to detect the subdomain and place a corresponding object in the request scope. Would it be possible to take it further and declare that the subdomain implements these urls but not those?

Something like?

if request.subdomain.is_blue:
     include(these.urls)

Upvotes: 0

Views: 1247

Answers (2)

Javier
Javier

Reputation: 62651

the urlconf is executed at startup time, not for each request; so you don't have the opportunity to include or not according to the URL used to acess.

the best would be to write your own middleware, or a restricting decorator (like @login_required), it's quite easy to write your own decorator (i like them more than middlewares for most specific tasks)

Upvotes: 5

oggy
oggy

Reputation: 3571

You can poke around with request.urlconf, but that can break things

Upvotes: 0

Related Questions