วันพุธที่ 29 มิถุนายน พ.ศ. 2559
การนำเนื้อหาจาก Page object มาแสดงในหน้าที่เราต้องการ
ในที่นี้เราจะนำเนื้อหาทั้งหน้าของ Page ซึ่งเป็น object ของ django cms มาแสดงในหน้าที่เราต้องการ วิธีการเป็นตามโค้ดด้านล่างนี้from cms.views import details from django.template import Context, Template
template_name = "your_page.html"
context = {}
page = get_object_or_404(Page, pk=page_id)
template = details(request, page.get_slug('en'))
content = ''
if hasattr(template, 'render'):
# TemplateResponse must call render() before we can get the content
content = template.render().content
else:
# HttpResponse does not have a render() method
content = template.content
t = Template(content)
c = Context({})
context['example_content'] = t.render(c)
return render(request, template_name, context)
สมัครสมาชิก:
ส่งความคิดเห็น
(
Atom
)
ไม่มีความคิดเห็น :
แสดงความคิดเห็น