本文整理汇总了Python中django.contrib.flatpages.models.FlatPage.delete方法的典型用法代码示例。如果您正苦于以下问题:Python FlatPage.delete方法的具体用法?Python FlatPage.delete怎么用?Python FlatPage.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.flatpages.models.FlatPage
的用法示例。
在下文中一共展示了FlatPage.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: flatpage
# 需要导入模块: from django.contrib.flatpages.models import FlatPage [as 别名]
# 或者: from django.contrib.flatpages.models.FlatPage import delete [as 别名]
def flatpage(request, url):
"""
Extended editable flat page view.
Models: `flatpages.flatpages`
Templates: Uses the template defined by the ``template_name`` field,
or `flatpages/default.html` if template_name is not defined.
Context:
flatpage
`flatpages.flatpages` object
"""
if not request.GET.get('action') in ('create', 'edit', 'delete'):
return flatpage_detail(request, url)
if not url.endswith('/') and settings.APPEND_SLASH:
return HttpResponseRedirect("%s/" % request.path)
if not url.startswith('/'):
url = "/" + url
f = get_object_or_none(FlatPage, url__exact=url, sites__id__exact=settings.SITE_ID)
if not f:
if not request.user.has_perm('flatpages.add_flatpage'):
raise Http404
f = FlatPage(url=url)
# If registration is required for accessing this page, and the user isn't
# logged in, redirect to the login page.
if f and f.registration_required and not request.user.is_authenticated():
from django.contrib.auth.views import redirect_to_login
return redirect_to_login(request.path)
if request.method == 'POST':
form = FlatPageEditForm(request.POST, instance=f)
if form.is_valid(): # All validation rules pass
f.save()
current_site = Site.objects.get_current()
if not current_site in f.sites.all():
# Assign page to current site
f.sites.add(current_site)
f.save()
msg = _("The %(verbose_name)s was updated successfully.") %\
{"verbose_name": FlatPage._meta.verbose_name}
messages.success(request, msg, fail_silently=True)
return HttpResponseRedirect(f.url)
else:
if request.GET.get('action') == 'delete':
f.delete()
msg = _("The %(verbose_name)s was deleted.") %\
{"verbose_name": FlatPage._meta.verbose_name}
messages.success(request, msg, fail_silently=True)
return HttpResponseRedirect('/')
form = FlatPageEditForm(instance=f)
if f.template_name:
t = loader.select_template((f.template_name, DEFAULT_TEMPLATE))
else:
t = loader.get_template(DEFAULT_TEMPLATE)
c = RequestContext(request, {
'form': form,
'flatpage': f,
})
response = HttpResponse(t.render(c))
populate_xheaders(request, response, FlatPage, f.id)
return response