Module 02 · Web App Deployment using Flask
Module 2 Lesson Summary: Web App Deployment using Flask模块 2 课时总结:使用 Flask 部署 Web 应用
Congratulations! You have completed this module. At this point, you know that:
祝贺您完成了本模块。此时,您已经知道:
- Python libraries are like toolkits. Each library has specific tools to simplify and expedite certain programming tasks. Frameworks are predefined structures for application development. Framework enables you to build the complete application, while libraries aid with specific functionality.
Python 库就像工具包。每个库都有特定的工具来简化和加速某些编程任务。框架是预定义的应用程序开发结构。框架使您能够构建完整的应用程序,而库则帮助实现特定的功能。 - Flask is a microframework that ships with minimal dependencies. To build websites, Flask has features like debugging servers, routing, templates, and error handling. Flask can be installed as a python package. Django is a full-stack framework compared to Flask. You can create a server by instantiating the Flask class.
Flask 是一个依赖项极少的微框架。为了构建网站,Flask 具有调试服务器、路由、模板和错误处理等功能。Flask 可以作为 Python 包进行安装。与 Flask 相比,Django 是一个全栈框架。您可以通过实例化 Flask 类来创建服务器。 - Flask provides a Request and a Response object for each client call. You can get additional information from the Flask Request, like headers. You can parse the Request Object to get query parameters, body, and other arguments. You can even set status on Response objects before sending a response back to the client.
Flask 为每个客户端调用提供 Request 和 Response 对象。您可以从 Flask Request 中获取附加信息,例如头部信息。您可以解析 Request 对象以获取查询参数、正文和其他参数。甚至在将响应发送回客户端之前,您都可以在 Response 对象上设置状态。 - You can use dynamic routes to create RESTful endpoints.
您可以使用动态路由来创建 RESTful 端点。 - There are multiple classes of HTTP status codes showing success, user error, or server error. Flask implicitly returns a success code of 200 with the response. You can also provide status codes explicitly. Flask also provides application-level error handlers.
存在多种 HTTP 状态代码类别,用于表示成功、用户错误或服务器错误。Flask 会隐式地在响应中返回 200 的成功代码。您也可以显式地提供状态代码。Flask 还提供了应用程序级别的错误处理器。 - Flask is a microframework for creating web applications and supports CRUD.
Flask 是一个用于创建 Web 应用的微框架,并支持 CRUD 操作。 - Install the Flask package using pip.
使用 pip 安装 Flask 包。 - To create a web application using Flask:
使用 Flask 创建 Web 应用程序:- Import Flask 导入 Flask
- Instantiate Flask 实例化 Flask
- Run the app 运行应用程序
- You can render both static and dynamic templates with Flask.
您可以使用 Flask 渲染静态和动态模板。