of the application. in this way, you can find the resource file from this path.You can see more complex application instance initialization later, but it is sufficient for simple applications.
2. routing and view functionsA client, for example, a web browser, sends requests to the web service and then sends them to the Flask application instance. The application instance needs to know the code to be run for each URL request, so it creates a URLs ing
configuration object. Another useful option is sqlalchemy_commit_on_teardown, which can be set to true to enable autocommit database changes in each request. Consult the Flask-sqlalchemy documentation for additional configuration options.
From flask.ext.sqlalchemy Import sqlalchemybasedir = Os.path.abspath (Os.path.dirname (__file__)) app = Flask (__name__) app.
the config.py file in the root directory and will load only variables in the file that are named uppercase
#!/usr/bin/env python#-*-coding:utf-8-*-"" "# # authors:limanman# 51ctobg:http://xmdevops.blog.51cto.com/# Purpose:# "" "from __future__ Import absolute_import# Description: Import Public Module # Description: Import other modules author = ' Limanman '
#!/usr/bin/env python#-*-coding:utf-8-*-"" "# # authors:limanman# 51ctobg:http://xmdevops.blog.51cto.com/# Purpose:# "" "# Desc
.
WSGI server: Although Flask has a built-in simple WSGI server, its performance is only applicable to debugging in the development phase. The Flask website recommends a variety of WSGI servers, from multi-process to multi-thread to coroutine, which will not be covered in this course.
REST adaptability: Although Flask is the same as Django, the initial starting p
Forms are the basic elements that let users interact with our web application. Flask itself does not help us with the form, but the FLASK-WTF extension lets us use the popular wtforms package in our Flask application. This package makes it easier to define forms and handle submissions.
Flask-wtfThe first thing we want
file, the template engine is responsible for rendering the response data, and then returned by flask response data to the browser, the last browser processing returned results displayed to the client.
Example: New file hello.py:
#coding: Utf-8
# import Flask Class
From Flaskimport Flask
# Flask class receives a param
Implicit response:1. The return value of the view function is implicitly converted to a response object2. If a valid response object is returned, it is returned directly from the view function3. If a string is returned, the string is created with the string data and the default argument as the body, and the status code is a Werkzeug.wrappers.Response response object of type 200,mime text/html4. If a tuple is returned (response, status, headers) and contains at least one element, the status value
;values_quoted.append (BaseConverter.to_url ( Value)) returnself.separator.join (values_quoted) app =flask (__name__) app.url_map.converters.update ({ ' list ': listconverter}) @ App.route ('/r/
Note: Classes that inherit Werkzeug.routing.BaseConverter must implement two methods To_python (value), which defines how the matching path passes through the view function, To_url (value), It defines the enco
from Flask import flask App = flask (__name) @app. Route ('/ ') def index (): return ' if __name__ = = '__main__': App.run ( Debug = True)Then execute Pyhont hello.py in the command line and enter 127.0.0.1:5000/in the browser to see the word HelloWorld.Code AnalysisFir
internal flask ).
1. config principles
2. routing principle
3. Wsgi interface call
4. understand session
5. understand threading. local
6. understand the thread local encapsulated by flask.
7. understand g and request
8. to understand app context and request context, you must first like pocoo. the pocoo documentation is very standard and clearly explained. We r
Blog Project Source: Https://github.com/JmilkFan/JmilkFan-s-Blog Directory
Table of Contents list put request delete request test Update operation on an existing posts record delete a record
List of the preceding text
Use flask to write a light blog (1)-Create a projectUse flask to write a light blog (2)-hello world.Use flask to write a light blog (3)-(M) vc_ con
HttpResponse in 1.FlaskThe HttpResponse in flask, in our view, is actually a direct return string.REDIRECT in 2.FlaskWhenever the address "/redi" is accessed, the View function Redi will trigger redirect ("/") to jump to the URL address: "/" and will trigger the "/" Corresponding view function index ()Render (Render_template) in 3.FlaskHTML template rendering is a must in every web framework, as for the specific use of render_template, leave a suspens
87. flask-script component of flask, flaskflask-script
The Flask Script extension provides the ability to insert external scripts to Flask, including running a development server, a custom Python shell, setting database scripts, cronjobs, and other command line Tasks running outside of web applications; Separate script
This part is still belong to the template, speak flask embedded bootstrap, use Flask-bootstrap plug-in. The meaning of this plugin is to simplify this embedded operation, of course not. Integrated Bootstrap via Flask-bootstrapBootstrap's introduction will not turn over. Bootstrap as a client side of the framework, he eventually exists in the HTML file, do
definition: The Ask extension encapsulates the SQLAlchemy framework. In Flask-sqlalchemy, the database is specified using a URL, and the following table lists the common database engines and the corresponding URLs. Installation: Pip Install Flask-sqlalchemyPip Install Flask-migrate# Boot filefromFlask_scriptImportManager,server fromFlask_migrateImportmigratecomma
_ (map) self. regex = regex def to_python (self, value): "when the route match is successful, the value of the parameter passed to the view function: param value: return: "" return int (value) def to_url (self, value): "When url_for is used to reverse generate a URL, the passed parameters are processed by this method, the returned value is used to generate the parameter param value: return: "val = super (RegexConverter, self) in the URL ). to_url (value) return val # add it to the converts
embedding data directly in your code. Moving report logic into template processing can improve the maintainability of your application. A template is actually a text with some dynamic parts that contain variables that can be known when the request context is in the content. To replace these variables with actual values, the process of eventually generating a response string is called rendering. Flask uses a powerful JINJA2 to handle render template t
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.