本文整理汇总了Python中models.Page.get_absolute_url方法的典型用法代码示例。如果您正苦于以下问题:Python Page.get_absolute_url方法的具体用法?Python Page.get_absolute_url怎么用?Python Page.get_absolute_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Page
的用法示例。
在下文中一共展示了Page.get_absolute_url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_absolute_url [as 别名]
def edit(request, name):
"""Allows users to edit wiki pages."""
try:
page = Page.objects.get(name=name)
except Page.DoesNotExist:
page = None
if request.method == 'POST':
form = PageForm(request.POST)
if form.is_valid():
if not page:
page = Page()
page.name = form.cleaned_data['name']
page.save()
revision = Revision()
revision.page = page
revision.content = form.cleaned_data['content']
if request.user.is_authenticated():
revision.editor = request.user
revision.save()
return HttpResponseRedirect(page.get_absolute_url())
else:
if page:
revision = page.get_latest_revision()
form = PageForm(initial={'name': page.name, 'content': revision.content})
else:
form = PageForm(initial={'name': name})
ctx = { 'form': form }
return render_to_response('wiki/edit.html', ctx, context_instance=RequestContext(request))
示例2: edit_page
# 需要导入模块: from models import Page [as 别名]
# 或者: from models.Page import get_absolute_url [as 别名]
def edit_page(request, slug):
try:
page = Page.objects.get(title_slug=slug)
except Page.DoesNotExist:
page = Page()
page.title = slug
page.title_slug = slug
if update_post_with_request(page, request, update_user=True, force_slug=False):
return HttpResponseRedirect(page.get_absolute_url())
else:
return render_req_to_resp(request, 'post_edit.html', {'post': page})