- Flask Framework Cookbook
- Shalabh Aggarwal
- 152字
- 2021-08-05 17:17:21
Introduction
In Flask, we can write a complete web application without the need of any third-party templating engine. For example, have a look at the following code; this is a simple Hello World application with a bit of HTML styling included:
from flask import Flask app = Flask(__name__) @app.route('/') @app.route('/hello') @app.route('/hello/<user>') def hello_world(user=None): user = user or 'Shalabh' return ''' <html> <head> <title>Flask Framework Cookbook</title> </head> <body> <h1>Hello %s!</h1> <p>Welcome to the world of Flask!</p> </body> </html>''' % user if __name__ == '__main__': app.run()
Is the preceding pattern of writing the application feasible in the case of large applications that involve thousands of lines of HTML, JS, and CSS code? Obviously not!
Here, templating saves us because we can structure our view code by keeping our templates separate. Flask provides default support for Jinja2, although we can use any templating engine as suited. Furthermore, Jinja2 provides many additional features that make our templates very powerful and modular.
推薦閱讀
- Practical Data Analysis Cookbook
- 算法精粹:經(jīng)典計(jì)算機(jī)科學(xué)問(wèn)題的Python實(shí)現(xiàn)
- Hadoop+Spark大數(shù)據(jù)分析實(shí)戰(zhàn)
- Mastering Apache Spark 2.x(Second Edition)
- Natural Language Processing with Java and LingPipe Cookbook
- Mastering Web Application Development with AngularJS
- Access 2010中文版項(xiàng)目教程
- Unity&VR游戲美術(shù)設(shè)計(jì)實(shí)戰(zhàn)
- Qt5 C++ GUI Programming Cookbook
- Laravel Application Development Blueprints
- Java Web從入門(mén)到精通(第2版)
- Java 從入門(mén)到項(xiàng)目實(shí)踐(超值版)
- 精通Spring:Java Web開(kāi)發(fā)與Spring Boot高級(jí)功能
- PHP+MySQL Web應(yīng)用開(kāi)發(fā)教程
- Learning D3.js 5 Mapping(Second Edition)