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.