Python Flask basic tutorial sample code, pythonflask

Source: Internet
Author: User

Python Flask basic tutorial sample code, pythonflask

This article focuses on the basic tutorial of Python Flask, which is described as follows.

Installation:pip install flaskYou can.

A simple Flask

From flask import Flask # import Flaskapp = Flask (_ name _) # create a Flask instance # Set the route, that is, the url@app.route ('/') # def hello_world (): # return 'Hello World! '# This is not run when the module is imported. For example, if the file is aa. py, the code is executed when python aa. py is used. If it is in another file import, do not execute this file. (This is the basic knowledge of python) if _ name _ = '_ main _': app. run ()
Enable debugging mode

Change app. run () to app. run (debug = True. In this way, you do not need to restart the server every time you modify the code.

Running result:

Advantages and disadvantages:

This is basically the case for a simple web build, Which is lightweight. Compared with Django, URLs, views, modles, and templatetags are all customized. Django is set.

However, the Flask learning cost is low. You can get started soon.

The two have their own characteristics. However, on the whole, I prefer Django. After all, it is more standardized.Although Flask is fast for small websites, and the file is relatively simple, there are not as many files as Django. However, it is difficult to add and expand the website later.

In general, there is no good or bad. Only by looking at the needs of the actual situation can we determine the framework to choose. The right is the best.

Summary

This article describes all the sample code in the basic Python Flask tutorial. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.