The first web environment built by python

Source: Internet
Author: User

To create a series of things, such as a project, all save points

# coding = Utf-8
# flask is a python-written web micro-framework that enables you to quickly implement a Web site or Web service using the Python language.
From flask import Flask

# Initialize Flask
App = Flask (__name__)


# The route access path created is empty
@app. Route ("/")
Def home ():
Return to "Hello World"


# App.run () code is optional The default port number is 5000, personal preference
if __name__ = = "__main__":
App.run (host= "localhost", port= ", debug=true)

Normal operation result

If you are returning an HTML page, import send_file
From flask Import Send_file
@app. Route ("/")
Def home ():
Return Send_file (".. /static/index.html ")
Web page back to normal because there's only one helloword on this side, index.html.
Loading when the introduction of CSS, JS, static pictures, etc... needs to be handled.

Create a folder at the root of the project put all the static resources into the access path by default change to/static/xxx/xxx.css or
/static/xxx/xxx.jpg, etc.

The final result of the visit is

Static resources are documented.
Of course, you can also use url_for constructs, such as code
Url_for ("Static", Filename= "Css/demo.css")

The first web environment built by python

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.