from django.views.generic.detail import DetailView from django.contrib.auth.forms import AuthenticationForm from pages.models import Page class PageDetailView(DetailView): model = Page slug_field = "slug" def get_template_names(self): obj = self.get_object() return ["pages/%s.html" % obj.slug, 'pages/page.html'] def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) if self.request.user.is_anonymous: context['login_form'] = AuthenticationForm() return context