本文整理汇总了Python中django.contrib.flatpages.models.FlatPage方法的典型用法代码示例。如果您正苦于以下问题:Python models.FlatPage方法的具体用法?Python models.FlatPage怎么用?Python models.FlatPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.flatpages.models
的用法示例。
在下文中一共展示了models.FlatPage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: flatpage
# 需要导入模块: from django.contrib.flatpages import models [as 别名]
# 或者: from django.contrib.flatpages.models import FlatPage [as 别名]
def flatpage(request, url):
"""
Public interface to the flat page view.
Models: `flatpages.flatpages`
Templates: Uses the template defined by the ``template_name`` field,
or :template:`flatpages/default.html` if template_name is not defined.
Context:
flatpage
`flatpages.flatpages` object
"""
if not url.startswith('/'):
url = '/' + url
site_id = get_current_site(request).id
try:
f = get_object_or_404(FlatPage, url=url, sites=site_id)
except Http404:
if not url.endswith('/') and settings.APPEND_SLASH:
url += '/'
f = get_object_or_404(FlatPage, url=url, sites=site_id)
return HttpResponsePermanentRedirect('%s/' % request.path)
else:
raise
return render_flatpage(request, f)
示例2: flatpage
# 需要导入模块: from django.contrib.flatpages import models [as 别名]
# 或者: from django.contrib.flatpages.models import FlatPage [as 别名]
def flatpage(request, url):
"""
Public interface to the flat page view.
Models: `flatpages.flatpages`
Templates: Uses the template defined by the ``template_name`` field,
or :template:`flatpages/default.html` if template_name is not defined.
Context:
flatpage
`flatpages.flatpages` object
"""
if not url.startswith('/'):
url = '/' + url
site_id = get_current_site(request).id
try:
f = get_object_or_404(FlatPage,
url=url, sites=site_id)
except Http404:
if not url.endswith('/') and settings.APPEND_SLASH:
url += '/'
f = get_object_or_404(FlatPage,
url=url, sites=site_id)
return HttpResponsePermanentRedirect('%s/' % request.path)
else:
raise
return render_flatpage(request, f)
示例3: setUp
# 需要导入模块: from django.contrib.flatpages import models [as 别名]
# 或者: from django.contrib.flatpages.models import FlatPage [as 别名]
def setUp(self):
self.page = FlatPage(title='Café!', url='/café/')