In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use Microsoft's free application services to build Python websites". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Sometimes we write a simple web page using Flask or Django and want to deploy it for everyone to use, but there is no server. At this time, in addition to buying a cloud service, we can also use the free application service provided by Microsoft Azure to deploy.
First, let's write a very simple back-end interface using Flask, as shown in the following figure:
Now, I don't want to buy a server, but I want to deploy it to the Internet. At this point, we can use the application service function of Azure.
First of all, let's apply for an Azure account. The official website of Azure is: Microsoft Azure [1]. We just need to sign up for an account just like an ordinary website. After signing up, Azure will give you a free cloud server for 12 months, as shown in the following figure. You can do a lot of things with this server. But we don't need this cloud server today.
Once we have an Azure account, we need to install something called Azure-cli. For installation instructions for Azure-cli, please refer to: Install the Azure CLI | Microsoft Docs [2]. Just check the installation instructions here according to your operating system. I'll take macOS as an example and use Homebrew to install:
Brew install azure-cli
After the installation is complete, we need to log in to the account using azure-cli and enter:
Az login
At this point, a web page pops up and you can log in to the account you just registered. After the login is complete, the web page displays the following:
The terminal window appears as shown in the following figure:
Next, deployment is about to begin. First go to the root directory of the Flask project we just created in the terminal and make sure you have the following two files: requirements.txt and app.py. Where requirements.txt can be exported with the following command:
Pip freeze > requirements.txt
At this point, it reflects the importance of creating a virtual environment, with a virtual environment, then only the third-party libraries needed by the project will be derived, and irrelevant libraries will not be exported.
And app.py is the entry program of the website, that is, the program where we set the FLASK_APP environment variable to point to.
Once these two things are in place, we only need to execute the following command:
Az webapp up-- sku F1-- name kingname
Where-- sku F1 must have this parameter, indicating the use of a free pricing strategy. If you don't add this parameter, Azure will deploy your site to a charging strategy.
And-- name kingname means your project is called kingname. The whole deployment process is about 2 minutes. The running effect is shown in the following figure:
Now, let's visit: http://kingname.azurewebsites.net to see the website you just deployed:
Next, we need to update the back-end code:
When you change the code and want to redeploy, you just need to execute it again:
Az webapp up
You can easily update the website program. As shown in the following figure:
This application service of Azure natively supports the direct deployment of Django and Flask websites. If you are using another back-end framework, or if your program is not a website, but a long-running ordinary Python script, it doesn't matter, the application service also provides the ability to specify startup commands. For specific operation, you can read its official document: configure Linux Python application-Azure App Service | Microsoft Docs [3]. You can also click "read the original text" in the lower left corner to open the help document of the Azure application service directly.
This is the end of the content of "how to use Microsoft's free application services to build a Python website". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.