from django.views.generic.detail import DetailView
from django.contrib.sites.models import get_current_site
from django import template
from django.utils import timezone

from .models import FlatPage


class PageDetail(DetailView):

    model = FlatPage
    context_object_name = "context"
    type = 'pages'

    @property
    def template_name(self):
        domain_folder = self.type
        if self.site.id > 1:
            domain_folder = "{0}/{1}".format(self.site, self.type)

        try:
            _template = '{0}/{1}.html'.format(
                domain_folder, self.page.get().slug)
            template.loader.get_template(_template)
        except template.TemplateDoesNotExist:
            _template = '{0}.html'.format(domain_folder)
        return _template

    @property
    def queryset(self):
        self.site = get_current_site(self.request)
        self.slug = self.kwargs.get('slug')

        self.page = self.model.objects.filter(
            site=self.site,
            slug=self.slug,
            date_available__lte=timezone.now(),
            published=True)
        return self.page

from django.views.generic.detail import DetailView
from django.contrib.sites.models import get_current_site
from django.utils import timezone

from .models import FlatPage


class PageDetail(DetailView):

    model = FlatPage
    context_object_name = "context"
    type = 'flatpages'

    @property
    def template_name(self):
        domain_folder = self.type
        if self.site.id > 1:
            domain_folder = "{0}/{1}".format(self.site, self.type)

        _template = '{0}/{1}.html'.format(
            domain_folder, self.page.get().slug)
        return _template

    @property
    def queryset(self):
        self.site = get_current_site(self.request)
        self.slug = self.kwargs.get('slug')

        self.page = self.model.objects.filter(
            site=self.site,
            slug=self.slug,
            date_available__lte=timezone.now(),
            published=True)
        return self.page

Fix template load on PageDetail flatpages app
Fix template load on PageDetail flatpages app

  from django.views.generic.detail import DetailView
  from django.contrib.sites.models import get_current_site
- from django import template
  from django.utils import timezone
  
  from .models import FlatPage
  
  
  class PageDetail(DetailView):
  
      model = FlatPage
      context_object_name = "context"
-     type = 'pages'
+     type = 'flatpages'
  
      @property
      def template_name(self):
          domain_folder = self.type
          if self.site.id > 1:
              domain_folder = "{0}/{1}".format(self.site, self.type)
  
-         try:
-             _template = '{0}/{1}.html'.format(
+         _template = '{0}/{1}.html'.format(
-                 domain_folder, self.page.get().slug)
+             domain_folder, self.page.get().slug)
-             template.loader.get_template(_template)
-         except template.TemplateDoesNotExist:
-             _template = '{0}.html'.format(domain_folder)
          return _template
  
      @property
      def queryset(self):
          self.site = get_current_site(self.request)
          self.slug = self.kwargs.get('slug')
  
          self.page = self.model.objects.filter(
              site=self.site,
              slug=self.slug,
              date_available__lte=timezone.now(),
              published=True)
          return self.page
  
Fix template load on PageDetail flatpages app
## Code Before:
from django.views.generic.detail import DetailView
from django.contrib.sites.models import get_current_site
from django import template
from django.utils import timezone

from .models import FlatPage


class PageDetail(DetailView):

    model = FlatPage
    context_object_name = "context"
    type = 'pages'

    @property
    def template_name(self):
        domain_folder = self.type
        if self.site.id > 1:
            domain_folder = "{0}/{1}".format(self.site, self.type)

        try:
            _template = '{0}/{1}.html'.format(
                domain_folder, self.page.get().slug)
            template.loader.get_template(_template)
        except template.TemplateDoesNotExist:
            _template = '{0}.html'.format(domain_folder)
        return _template

    @property
    def queryset(self):
        self.site = get_current_site(self.request)
        self.slug = self.kwargs.get('slug')

        self.page = self.model.objects.filter(
            site=self.site,
            slug=self.slug,
            date_available__lte=timezone.now(),
            published=True)
        return self.page

## Instruction:
Fix template load on PageDetail flatpages app
## Code After:
from django.views.generic.detail import DetailView
from django.contrib.sites.models import get_current_site
from django.utils import timezone

from .models import FlatPage


class PageDetail(DetailView):

    model = FlatPage
    context_object_name = "context"
    type = 'flatpages'

    @property
    def template_name(self):
        domain_folder = self.type
        if self.site.id > 1:
            domain_folder = "{0}/{1}".format(self.site, self.type)

        _template = '{0}/{1}.html'.format(
            domain_folder, self.page.get().slug)
        return _template

    @property
    def queryset(self):
        self.site = get_current_site(self.request)
        self.slug = self.kwargs.get('slug')

        self.page = self.model.objects.filter(
            site=self.site,
            slug=self.slug,
            date_available__lte=timezone.now(),
            published=True)
        return self.page
