I have multiple pages in my Django project.
Here's my urls.py
urlpatterns = [
path('page1', views.page1),
path('page2', views.page2),
path('page3', views.page3),
]
I want to add a redirect that applies to all the pages so that users that aren't authenticated will be redirected to MSOAuth2.
Here's my views.py
def page1(request):
return render(request, "page1.html")
def page2(request):
return render(request, "page2.html")
def page3(request):
return render(request, "page3.html")
def MS_OAuth2(request):
if not request.user.is_authenticated:
return redirect('https://login.microsoftonline.com/tenant/oauth2/v2.0/authorize?')
What regex or url pattern do I need to use so all my pages can redirect to views.MS_OAuth2?
This is what I have so far but it's not working. I want the redirect to apply to all pages in my website.
urlpatterns = [
path('page1', views.page1),
path('page2', views.page2),
path('page3', views.page3),
path(r'^$', views.MS_OAuth2)
]
Thank you!