[Flask] Learning Essays--templates

Source: Internet
Author: User

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

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.