《Flask Web Development》的原文摘录

  • To start using the virtual environment, you have to “activate” it. If you are using a bash command line (Linux and Mac OS X users), you can activate the virtual environment with this command: (查看原文)
    [已注销] 2014-11-27 00:18:20
    —— 引自第5页
  • When a virtual environment is activated, the location of its Python interpreter is added to the PATH, but this change is not permanent; it affects only your current command session. To remind you that you have activated a virtual environment, the activation command modifies the command prompt to include the name of the environment: (查看原文)
    [已注销] 2014-11-27 00:18:20
    —— 引自第5页
  • When you are done working with the virtual environment and want to return to the global Python interpreter, type deactivate at the command prompt. (查看原文)
    [已注销] 2014-11-27 00:18:20
    —— 引自第5页
  • The name argument that is passed to the Flask application construc‐ tor is a source of confusion among new Flask developers. Flask uses this argument to determine the root path of the application so that it later can find resource files relative to the location of the application. (查看原文)
    [已注销] 2014-11-27 00:25:43
    —— 引自第7页
  • @app.route(404) def page_not_found(e): return render_template('404.html'),404 @app.route(500) def internal_server_error(e): return render_template('500.html'),500 (查看原文)
    Max 2015-07-18 16:31:10
    —— 引自第17页
  • PyCharm 2016.1 or 2016.2:Settings,Tools,Terminal, and add""/K <path-to-your-activate.bat>""toShell path and add (mind the quotes). Also add quotes around cmd.exe, resulting in: `"cmd.exe" /k ""C:\mypath\my-venv\Scripts\activate.bat""` (查看原文)
    落花流水 2016-10-13 15:39:41
    —— 引自第6页
  • Web服务器网关接口(Python Web Server Gateway Interface,缩写为WSGI)是为Python语言定义的Web服务器和Web应用程序或框架之间的一种简单而通用的接口。自从WSGI被开发出来以后,许多其它语言中也出现了类似接口。WSGI是作为Web服务器与Web应用程序或应用框架之间的一种低级别的接口,以提升可移植Web应用开发的共同点。WSGI是基于现存的CGI标准而设计的。 WSGI区分为两个部份:一为“服务器”或“网关”,另一为“应用程序”或“应用框架”。在处理一个WSGI请求时,服务器会为应用程序提供环境资讯及一个回呼函数(Callback Function)。当应用程序完成处理请求后,透过前述的回呼函数,将结果回传给服务器。所谓的 WSGI 中间件同时实现了API的两方,因此可以在WSGI服务和WSGI应用之间起调解作用:从WSGI服务器的角度来说,中间件扮演应用程序,而从应用程序的角度来说,中间件扮演服务器。“中间件”组件可以执行以下功能: 重写环境变量后,根据目标URL,将请求消息路由到不同的应用对象。 允许在一个进程中同时运行多个应用程序或应用框架。 负载均衡和远程处理,通过在网络上转发请求和响应消息。 进行内容后处理,例如应用XSLT样式表。 (查看原文)
    落花流水 2016-10-13 22:19:33
    —— 引自第7页
  • Why is that? The application will work even with __name__, thanks to how resources are looked up. However it will make debugging more painful. Certain extensions can make assumptions based on the import name of your application. For example the Flask-SQLAlchemy extension will look for the code in your application that triggered an SQL query in debug mode. If the import name is not properly set up, that debugging information is lost. (For example it would only pick up SQL queries in yourapplication.app and not yourapplication.views.frontend) (查看原文)
    落花流水 2016-10-13 22:19:33
    —— 引自第7页
  • 每一段程序都有很多外部变量。只有像Add这种简单的函数才是没有外部变量的。一旦你的一段程序有了外部变量,这段程序就不完整,不能独立运行。你为了使他们运行,就要给所有的外部变量一个一个写一些值进去。这些值的集合就叫上下文。 (查看原文)
    落花流水 2016-10-21 15:58:03
    —— 引自第15页
  • >> from hello import app >> from flask import current_app >> app_ctx = app.app_context() >> app_ctx.push() >> current_app.name 'hello' >> app_ctx.pop() ``` (查看原文)
    落花流水 2016-10-21 15:58:03
    —— 引自第15页
  • PyCharm 2016.1 or 2016.2:Settings,Tools,Terminal, and add""/K <path-to-your-activate.bat>""toShell path and add (mind the quotes). Also add quotes around cmd.exe, resulting in: `"cmd.exe" /k ""C:\mypath\my-venv\Scripts\activate.bat""` (查看原文)
    落花流水 2016-10-22 08:36:38
    —— 引自第6页
  • Web服务器网关接口(Python Web Server Gateway Interface,缩写为WSGI)是为Python语言定义的Web服务器和Web应用程序或框架之间的一种简单而通用的接口。自从WSGI被开发出来以后,许多其它语言中也出现了类似接口。WSGI是作为Web服务器与Web应用程序或应用框架之间的一种低级别的接口,以提升可移植Web应用开发的共同点。WSGI是基于现存的CGI标准而设计的。 WSGI区分为两个部份:一为“服务器”或“网关”,另一为“应用程序”或“应用框架”。在处理一个WSGI请求时,服务器会为应用程序提供环境资讯及一个回呼函数(Callback Function)。当应用程序完成处理请求后,透过前述的回呼函数,将结果回传给服务器。所谓的 WSGI 中间件同时实现了API的两方,因此可以在WSGI服务和WSGI应用之间起调解作用:从WSGI服务器的角度来说,中间件扮演应用程序,而从应用程序的角度来说,中间件扮演服务器。“中间件”组件可以执行以下功能: 重写环境变量后,根据目标URL,将请求消息路由到不同的应用对象。 允许在一个进程中同时运行多个应用程序或应用框架。 负载均衡和远程处理,通过在网络上转发请求和响应消息。 进行内容后处理,例如应用XSLT样式表。 (查看原文)
    落花流水 2016-10-22 08:41:32
    —— 引自第7页
  • Why is that? The application will work even with __name__, thanks to how resources are looked up. However it will make debugging more painful. Certain extensions can make assumptions based on the import name of your application. For example the Flask-SQLAlchemy extension will look for the code in your application that triggered an SQL query in debug mode. If the import name is not properly set up, that debugging information is lost. (For example it would only pick up SQL queries in yourapplication.app and not yourapplication.views.frontend) (查看原文)
    落花流水 2016-10-22 08:41:32
    —— 引自第7页
  • 每一段程序都有很多外部变量。只有像Add这种简单的函数才是没有外部变量的。一旦你的一段程序有了外部变量,这段程序就不完整,不能独立运行。你为了使他们运行,就要给所有的外部变量一个一个写一些值进去。这些值的集合就叫上下文。 (查看原文)
    落花流水 2016-10-22 08:45:12
    —— 引自章节:Chap.2-The Request-Response Cy
  • python-3.5.2 (查看原文)
    落花流水 2016-11-08 21:47:28
    —— 引自第189页
  • >>> user_role = Role.query.filter_by(name='User').first() filter_by() 等过滤器在 query 对象上调用,返回一个更精确的 query 对象。多个过滤器可 以一起调用,直到获得所需结果。 (查看原文)
    sindwerra 2018-02-27 21:39:42
    —— 引自第53页