1 # -*- coding: utf-8 -*-
2 from django.conf import settings
3 from django.contrib.flatpages.models import FlatPage
4 from django.contrib.flatpages.views import render_flatpage
5 from django.contrib.sites.models import get_current_site
6 from django.http.response import Http404, HttpResponsePermanentRedirect
7 from django.shortcuts import get_object_or_404
8 from django.views.generic import TemplateView
11 def flatpage_with_template(request, url, template_name):
13 Public interface to the flat page view.
15 Models: `flatpages.flatpages`
16 Templates: Uses the template defined by the ``template_name`` field,
17 or :template:`flatpages/default.html` if template_name is not defined.
20 `flatpages.flatpages` object
22 if not url.startswith('/'):
24 site_id = get_current_site(request).id
26 f = get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
28 if not url.endswith('/') and settings.APPEND_SLASH:
30 get_object_or_404(FlatPage, url__exact=url, sites__id__exact=site_id)
31 return HttpResponsePermanentRedirect('%s/' % request.path)
34 f.template_name = template_name
35 return render_flatpage(request, f)