14Flask important knowledge

First, Li "Flask Web development actual combat."

1, the network penetration

Network penetration tools can quickly make the project run flask:

1,https://localtunnel.github.io/www/

2, https://ngrok.com/

2, flask Configuration

Must be all uppercase, lowercase variables will not be read.

app.config['ADMIN_NAME'] = 'Peter'

3, converter

any converter:

4, the hook Request

Sometimes we need pre-treatment and post-treatment, it is necessary to use a hook request.

Another common application is to establish a database connection, usually have a plurality of views function requires
the establishment of a database connection and closed, these operations are substantially the same. An ideal solution is to
establish a connection before requesting (before_request), teardown_request after the request) closes the connection.

 5, HTTP status code

 6,abort

@app.route('/404/')
def not_found():
    abort(404)

abort function requires no return.

7, the context of global variables

Because g is stored in the program's context, and application context for each request will as the intake of
the activated, with the completion of the processing of each request and destruction, so each request to reset
the value.

 

8,Ajax

AJAX指异步JavascriptXMLAsynchronous JavaScript And
XML) , 它不是编程语言或通信协议, 而是一系列技术的组合体。 解决的问题:

每当页面状态需要变动, 或是需要更新数据时, 都伴随着一个发向
服务器的请求。 当服务器返回响应时, 整个页面会重载, 并渲染新页
面。 

 

Guess you like

Origin www.cnblogs.com/two-peanuts/p/11160593.html