Read about flask or django for web development, The latest news, videos, and discussion topics about flask or django for web development from alibabacloud.com
Introduction of Flask
Flask is a Python-implemented WEB development micro-framework. Official website: http://flask.pocoo.org/
Second, Demo
1, Code structure
Copy Code code as follows:
.
├──blog.py
├──static
│├──css
││└──index.css
│├──images
││├──cat.jpg
││└──sheying1229.jpg
│└──js
I. Introduction of FLASK
Flask is a Python-implemented WEB development micro-framework. Official website: http://flask.pocoo.org/
Second, Demo
1. Code structure
Copy the Code code as follows:
.
├──blog.py
├──static
│├──css
││└──index.css
│├──images
││├──cat.jpg
││└──sheying1229.jpg
│└──js
└──templates
├──index.html
├─
Needless to say, we directly introduce the contents of this open class.Main content:First, Web Development FoundationIi. "Hello World" in the FlaskThree, the Flask templateIv. message hints and exception handling for FlaskFirst, Web Development FoundationThis chapter focuses
Flask is a lightweight Web application framework written using Python. It is based on Werkzeug WSGI Toolkit and JINJA2 template engine. Flask uses BSD licensing.flask is based on Python's flexibility and provides a simple template for web development. Demo:flask Community
.
% (ThreadName) s
The name of the thread. Probably not.
% (process) d
The process ID. Probably not.
% (message) s
User-Output messages
3. View ResultsAfter running again, you can see the log record in the TXT file under the path we setHere we see there is a applogger, this is the name of the log, through Logger.name can set this name, such as:App.logger.name="Applogger"For details, please refer to the official documentation: Http
of the thread. Probably not.
% (process) d
The process ID. Probably not.
% (message) s
User-Output messages
3. View ResultsAfter running again, you can see the log record in the TXT file under the path we setHere we see there is a applogger, this is the name of the log, through Logger.name can set this name, such as:App.logger.name="Applogger"For details, please refer to the official documentation: Https://docs.python.org/3/library/logging.html#log
Python Web framework Flask: website development entry instance, pythonflask
1. Introduction to Flask
Flask is a Web development microframework implemented by Python. Official Website: h
, be sure to choose the executable file for Python, such as the path on my computer is D:\Postgraduate\Python\Virtualenv\flask-env\Scripts\python.exe# # # Set Debug mode1. In App.run (), pass in a keyword parameter debug,app.run (debug=true), set the current project to debug modeTwo main functions of 2.debug mode:* When there is a problem with the program, you can see the error message and the error location on the page.* As long as the ' Python ' fil
SqlAlchemyis aPythonof theOrmFramework. There is a flask-sqlalchemy extension in flask , which is convenient to use. 1. Create a sqlalchemy the Model ModuleTo create a models.py module When creating the model, first introduce the extension of Flask-sqlalchemy from Flask Import
= Article.query.filter (Article.title = = ' aaa '). First () ##2. Take this data and change it where you want it. #article1.title = ' new title ' ##3. Commit a transaction #Db.session.commit () ##删: ##1. Find out the data you need to delete #article1 = Article.query.filter (article.content = = ' BBB '). First () ##2. Erase this data. #Db.session.delete (article1) ##3. Do a transaction commit #Db.session.commit () return 'Hello world!'if __name__=='__main__':
isNone:user= User (username = form.name.data,email=form.email.data,password=form.password.data)#Insert a row if it does not exist
db.session.add (user) Db.session.commit ()#these two lines are necessary.session['known'] =FalseElse: session['known'] =True session['name']=Form.name.data Form.name.data="'
returnRender_template ('index.html', Form=form,name=session.get ('name'), known = Session.get ('known', False)) if __name__=='__main__': App.run (Debug=true) Of course, our template rendering
'Hello world!'@app. Route ('/list/')defmy_list ():return 'List'@app. Route ('/article/')defarticle (ID):return 'the ID of your request is:%s'%IDif __name__=='__main__': App.run (Debug=true)The output gets:Note that here the article function, has the ID parameter, in the Url_for function needs to pass in the parameter, otherwise will error# # # Reverse URL:1. What is called Reverse URL: A conversion from a view function to a URL is called a reverse URL2. Reverse the use of URLs:* The URL reversa
both contexts before scheduling each request, and the request is processed and removed. When the application context is push, its corresponding two variables can be accessed by the thread, and the request context is the same. Of course, if these contexts are not activated, accessing these variables will cause an error. As an example: >>>from flask Import flask, Current_app>>>app =
ObjectiveAfter reading "Django book", Always want to find an example to develop the actual combat, but the domestic Django books are quite few, only from the English books to absorb nutrients, accidentally after getting learning Website development with Django this book, Feel very good, although thinking of translation
SQLAlchemy is a Python ORM framework.There is a flask-sqlalchemy extension in flask, which is convenient to use.1. Create a sqlalchemy model moduleTo create a models.py moduleWhen creating the model, first introduce the extension of Flask-sqlalchemy from Flask Import flask f
The last time I learned the creation of the Helloword project of flask, this time to learn the template loading of flask project:First step: Create a Flask projectStep Two: Create an HTML file under the Templates folder in the project directoryStep three: Loading the template file here will use a template renderer under the f
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.