update$ Brew install pythonCreate a blog directory, generate an independent Python virtual environment, and install the required Flask and Flask-FlatPages modules in this environment:Copy codeThe Code is as follows:$ Mkdir blog$ Cd blog
$ Virtualenv flaskNew python executable in flask/bin/pythonInstalling setuptools, pip... done.
$
Python 2. x. support for Python 3 is coming for gevent, so the situation is likely to improve in the near future. (Update: Flask-SocketIO version 1.0 is fully compatible with Python 2.7 and 3.3 +, see bottom of the article for more information ).
The latest status is that Flask-SocketIO v1.0 can run on Python 2.7 and Python 3.3 +.
Below is an example Flask appl
server and a Web application or application framework to enhance the common denominator of portable web application development. WSGI is designed based on the existing CGI standards.Many frameworks have their own WSGI servers, such as Flask,webpy,django, CherryPy, and so on. Of course, the performance is not good, the Web server comes with more testing purposes, the release of the use of the production environment of the WSGI server or the joint ngin
Label:The Flask-sqlalchemy library makes it easier for Flask to use SQLAlchemy, a powerful relational database framework that can either manipulate the database using ORM or use the original SQL commands. Flask-migrate is a data migration framework that needs to be manipulated through the Flask-script library. I. Confi
for x in sys.meta_path if self != x] + [self] def find_module(self, fullname, path=None): if fullname.startswith(self.prefix): return self def load_module(self, fullname): modname = fullname.split('.', self.prefix_cutoff)[self.prefix_cutoff] for path in self.module_choices: realname = path % modname __import__(realname)
Iii. Principles of flask sqlalchemy
Sqlalchemy is the most powerful orm
): return Self.render (' admin/test.html ')
If the user accesses the index view, the template file admin/myindex.html will be rendered. Similarly, the result of accessing the Test view is that admin/test.html is rendered.
So how does this approach help to structure the management interface? With these built-in parts, you can implement highly customizable, reusable features.
For example, Flask-admin provides an off-the-shelf SQLAlchemy model interf
Flask-Migrate can help the Flask application to complete database migration through a preset Python script. here we will take a look at the tutorial on using Flask-Migrate to expand database migration in the Python Flask framework, when upgrading the system, you may need to update the data structure on the server. the
Tags: Introducing model ROM column REM move use register modSteps to use: 1. Introduction of Flask-sqlalchemyfrom
import SQLAlchemy
= SQLAlchemy () 2. Register flask-SQLAlchemy
db.init_app (APP) 3. Import the tables
in models from Import * 4. Write class inherits Db. Model
class Users (db. Model):
__tablename__'users'
= Column (Integer, Pri
In the Python Flask framework, use Flask-Migrate to expand the database migration tutorial, flaskflask-migrate
When upgrading the system, we often encounter operations such as updating the data structure on the server. The previous method was to manually write an alter SQL script for processing, and we often find omissions, as a result, the program cannot be used normally after being published to the server
register a Module?
The following example shows how the Flask application registers a Module.
1. Project Structure
The project structure of this simple example is as follows:
/myapplication /__init__.py /app.py /views /__init__.py /admin.py /blog.py
The code for the admin. py and blog. py modules is as follows:
# admin.pyfrom flask import Moduleadmin = Module(__name__)@admin.route('/')def index(
created in_ Init _. pyFile, then we can safely import and reference each package.
Setting. py: configuration file, database username and password, etc.
3. Develop code
1. Run the project first:
1) write the _ init _. py file to create a project object. The Code is as follows:
#-*-Coding: UTF-8-*-from flask import Flask # create a project object app =
:
{% extends 'admin/master.html' %}{% block body %} Hello World from AnotherMyAdmin!
If AnotherAdminView adds the parameter endpoint = 'xxx', you can write it as url_for ('xxx. text'). Then, the page URL changes from/admin/anotheradminview/to/admin/xxx.If the parameter url = 'aaa' is specified at the same time, the page URL will be/admin/aaa, And the url priority is higher than the endpointAdmin
Copy codeThe Code is as follows:Class Admin (app = None
'
The content in the angle brackets is dynamic content. Any URL that matches the static part will be mapped to this route.
The dynamic part of the route uses a string by default, but you can also use the type definition. For example,/usr/3. Start the server
if __name__ == '__main__': app.run(debug=True)
Some option parameters can be accepted by the app. run () function to set the operation mode of the web server. Enabling the debug mode during the
Interpretation of Flask source code (1) and flask source code
FlaskIs a lightweight Web application framework written in Python. Flask is only a bridge between Werkezug and Jinja2. The former implements a suitable WSGI application and the latter processes the template. Of course, Flask is also bound to some common stan
multi-process to multi-threaded to the association, this choice we will not be involved in this course.
Rest adaptability: Although flask and Django are the same, the initial starting point is the Dynamic Web application on the server side. But Flask's design makes it quite suitable for resource-oriented rest architectures, which is a considerable advantage of flask versus Django in the increasingly mobile
migration warehouseFirst, we want to install flask-migrate in a virtual environment:Pip Install Flask-migrateThe initialization method for this extension is as follows:from = Migrate (app, db) Manager.add_command ('db', Migratecommand)To export the database Migration command, Flask-migrate provides a Migratecommand cl
multi-process to multi-threaded to the association, this choice we will not be involved in this course.
Rest adaptability: Although flask and Django are the same, the initial starting point is the Dynamic Web application on the server side. But Flask's design makes it quite suitable for resource-oriented rest architectures, which is a considerable advantage of flask versus Django in the increasingly mobile
Flask series tutorials (8) -- Flask-Migrate, flaskflask-migrateFlask-Migrate
In the actual development environment, database changes often occur. Generally, we do not manually modify the database, but modify the database.ORMThe corresponding model, and then map the model to the database. At this time, it would be very useful to have a tool dedicated to this kind of thing.flask-migrateThis is what we do.flas
Overview
To develop a large project with flask, you must have a good project file structure, which records the configuration of the Flask minimum development project. The Python version used here is 3.5.1,flask version 0.11.1. test Environment Python version: 3.5.1 flask version: 0.11.1 pycharm version: 5.0.3 main dir
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.