- 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.
推薦閱讀
- Java完全自學教程
- PyQt從入門到精通
- Android開發:從0到1 (清華開發者書庫)
- C#應用程序設計教程
- R用戶Python學習指南:數據科學方法
- 寫給程序員的Python教程
- Hands-On Robotics Programming with C++
- C#面向對象程序設計(第2版)
- Android Studio開發實戰:從零基礎到App上線 (移動開發叢書)
- Java Web開發教程:基于Struts2+Hibernate+Spring
- ArcPy and ArcGIS(Second Edition)
- 用Python動手學統計學
- Building Apple Watch Projects
- Hands-On ROS for Robotics Programming
- HTML 5與CSS 3權威指南(第4版·上冊)