[Webpy] using the jinja2 template in Webpy

Source: Internet
Author: User

Webpy's template feels like writing a small page, but if you write more HTML tags will be very messy, so decided to use JINJA2, this template is similar to Django template, and other Pythonweb framework compatibility is better.

Create a new settings file under the project directory

#-*-coding:utf-8-*-__author__  = ' Orangleliu ' settings of the project ' Import Osimport Webfrom Web.contrib.template Import render_jinja#------------------debug----------------------debug = ' server_software ' not In os.environweb.config.debug = debug#------------------jinja2----------------------app_root = os.path.dirname (__ file__) Templates_path = Os.path.join (app_root, ' Templates '). replace (' \ \ ', '/') render = Render_jinja (    templates_ Path,    encoding= ' Utf-8 ')

To create a new templates folder under the project directory to hold the template file.


Use:

#-*-coding:utf-8-*-__author__ = ' Orangleliu ' filename:index.pycreate: @20140513index page handler of this app ' Impo RT webfrom Settings Import Renderclass index:    def GET (self):        web.header ("Content-type", "text/html")        Return Render.index ({})


The structure of the project file is as follows:



This makes it possible to use the JINJA2 template.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.