This learning note is mainly not to share experience, more is to record the experience of the Falsk process, after doing something in-depth research, because Django used longer, so many concepts are a look over, do a test to understand the function of the next flask.
Flask is a jinja2 template, similar to Django's own template, but more powerful than the Django template, providing more useful tools that are basically consistent with basic usage.
Wrote a small case, the basic steps of the template rendering and the basic use of the variable pass practice.
Jinjia2 Template Document http://jinja.pocoo.org/docs/dev/
Flask-bootstrap Document Http://pythonhosted.org/Flask-Bootstrap/
Code directory Structure:
Code Listing:
template_jinjia2.py
#-*-coding:utf-8-*-#python2.7x#author: [email protected] 2014-12-17#template_jijia2 ' simple use and familiarity with templates ' from flask Import Flask, render_templatefrom flask.ext.bootstrap Import Bootstrapapp = Flask (__name__) bootstrap = bootstrap (APP) @ App.route ('/') def index (): " test jinja2 Template Common variable representation" mydict = {"Name": "Orangleliu"} mylist = ["Apple", "orange", "banana"] class MyObj: def sayhello (self): return "Yes I am a method!" #这里使用了一个 flask-bootstrap to do as template basic style return render_template (' index.html ', mydict=mydict, Mylist=mylist, myobj=myobj) If __name__== "__main__": app.run (debug=true)
Index.html
{% extends "bootstrap/base.html"%}<!--overall page style can be inherited from the basic template-->{% block content%}
Bottom.html
<p> Copyright Orangleliu 2014</p>
Run
View Browser
With the template, we can handle a variety of get post requests with parameters, form requests, data manipulation.
This article is from the "Orangleliu Notebook" blog, reproduced please be sure to keep this source http://blog.csdn.net/orangleliu/article/details/41990573
Author Orangleliu using Attribution-NonCommercial-sharing protocol in the same way
[Flask] Learning Essays--templates