I'm building a simple web application with Django. My users are separated into multiple groups, for example Group A, Group B, etc.
What I want to do is to dynamically update urlpatterns list in urls.py so that I can have different views on same url endpoints.
For example, I'd like to do something like this (I know syntax is off, it's just to demonstrate what I want)
urlpatterns = [
url(r'^$', views.homepage, name='homepage'),
url(r'^login/$', views.BaseLogin.as_view(), name='core.login'),
url(r'^logout/$', views.logout, name='core.logout'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if request.user in groupA:
urlpatterns.append(url(r'^dash/', include('groupA.urls')))
else:
urlpatterns.append(url(r'^dash/', include('groupB.urls')))
How would I best achieve this?
I think this is neither possible nor desirable. You should place such logic in the view. Make both land in the same view and redirect or simply put together different content in the view based on the user's group affiliation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With