So I just learned Python/Django last weekend. What I'm trying to do is have url routes available with different content depending on who's logged in. So my usecase is I create 5 usernames/passwords and then those 5 users can login to read specific content/routes catered to them that no other user should be able to see.
Right now I have these routes with correlating views.
urlpatterns = [
url(r'^$', accounts.views.loginview),
url(r'^accounts/', include('accounts.urls')),
url(r'^sitepages/', include('sitepages.urls')),
]
I get the auth thing, I'm filtering content to only logged in users using @login_required, it looks like this :
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
@login_required
def attributes(request):
return render(request, 'sitepages/something.html')
I've researched how to have a different menu bar depending on the user, etc. But I haven't been able to find how to have entirely different routes and content pages depending on the user.
I think I'll need to do this using groups in Django and I think that I'll need to use the user's foreign key in order to cater the content. I created one group using admin, but I'm having a hard time consolidating my next step.
These are the resources I've checked out:
Django Database routing based on current user logged in
Django restrict pages to certain users
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Django/Authentication
https://docs.djangoproject.com/en/1.10/topics/auth/default/
I'm on Python version 3.6.0; Django version 1.10.6