Reputation: 163
I'm using TemplateView to display swagger pages (local files). However, now I need to restrict access. Using a normal view, I could use @login_required mixin on the view. Is there a way to do that with TemplateViews? Or should I be using some other way of displaying these swagger pages?
url(r'^swagger/', TemplateView.as_view(template_name='swagger.html'), name='swagger'),
Upvotes: 1
Views: 734
Reputation: 3610
The most clean way would be to create a view extending the TemplateView
, so it would help leaving your urls.py clean.
views.py
from django.contrib.auth.mixins import LoginRequiredMixin
class SwaggerView(LoginRequiredMixin, TemplateView):
template_name = 'swagger.html'
urls.py
from . import views
url(r'^swagger/', views.SwaggerView.as_view(), name='swagger'),
Upvotes: 2