current position:Home>Quickly build Django blog based on function calculation

Quickly build Django blog based on function calculation

2021-08-21 20:19:28 Alibaba cloud experience Lab

Introduction to the experience

This scenario describes how to use the function computing service to build a Django Blog Blog . Use Serverless Devs Command line tools can integrate many frameworks 、 application 、 The case is deployed to the function computing platform with one click .

This experiment One time is provided 2 Hours of ECS

Background knowledge

This scenario mainly involves the following cloud products and services :

1、 Function calculation (FunctionCompute)

Function computing is an event driven fully managed computing service . Use functions to calculate , You don't need to purchase and manage infrastructure like servers , Just write and upload the code . Function calculation is ready for you to calculate resources , Run tasks flexibly and reliably , And provide log query 、 Performance monitoring, alarm and other functions . Function calculations help you avoid managing servers (Serverless), Just focusing on function code can quickly build applications . Function computation can scale elastically , You just have to pay by usage .

Function calculation Serverless Compared with self built service, service has the following advantages :

1) Easy to get started , Focus on business logic development only , Greatly improve the efficiency of engineering development .

2) There are too many learning and configuration costs for self built programs , For example, for different scenarios ,ESS Various parameter configurations are needed , It is troublesome to maintain and upgrade the system environment .

3) No operation and maintenance , Support function execution level granularity monitoring and alarm .

4) Millisecond elastic expansion , Ensure high flexibility .

2、 Container image service ACR

Container mirroring service is container mirroring oriented 、Helm Chart Etc OCI Standard cloud native product security hosting and efficient distribution platform .ACR Support global synchronous acceleration 、 On a large scale / Big image distribution speeds up 、 Multi code source construction acceleration and other whole chain ways to improve efficiency , And container services ACK Seamless integration , Help enterprises reduce delivery complexity , Create a one-stop solution for cloud native applications .

3、 File store NAS

File store NAS Is a large-scale shared access , Elastic expansion of high-performance cloud native distributed file system . Support intelligent hot and cold data layering , Effectively reduce data storage costs . It is widely used in enterprise application data sharing 、 Containers 、AI machine learning 、Web Services and content management 、 Application development and testing 、 Media and entertainment workflow 、 Database backup and so on .

4、Serverless Devs Developer tools

Serverless Devs It is a component and plug-in Serverless Developer Platform , Developers can pluggably use different tools in the platform Serverless Services and frameworks for , Participate in the development of components and plug-ins at the same time . Whether it's industrial grade Serverless service , Or all kinds of open source Serverless frame ,Serverless Devs Can be friendly and supportive . Developers don't have to deal with every model on the market Serverless Tools for research and learning , Just pass Serverless Devs, It can be simple 、 Quickly “ Get started ” Main stream Serverless Services and frameworks .

1. Open function computing service

Before you use a function to calculate , You need to open the function calculation service .
explain :

The alicloud sub account provided in this scenario has no function computing service operation permissions , So please use your alicloud account to operate . You don't have to worry about the deduction , Because the function computing service has a certain amount of free , See billing method .

  1. Log in to the alicloud console with your own alicloud account , Then enter the function calculation details page .

    1. Click free to subscribe .

     Insert picture description here

    1. Check the function to calculate the service agreement , Click open now .

 Insert picture description here
After successful opening , You will receive the following prompt .
 Insert picture description here

2. install Serverless Devs Command line tools

install Node.js Environmental Science .

Execute the following command , download Node.js Installation package .


Execute the following command , Unzip the installation package and rename .

tar -xvf node-v12.4.0-linux-x64.tar.xz && mv node-v12.4.0-linux-x64/ /usr/local/node

Execute the following command , Configure environment variables .

echo "export PATH=$PATH:/usr/local/node/bin" >> /etc/profile
source /etc/profile

Execute the following command , install Serverless-Devs Tools .

npm install @serverless-devs/s -g

The results are as follows , Indicates installation is complete .
 Insert picture description here
explain :
If the installation process is slow , You can use Taobao npm Source , The installation command is npm --registry= install @serverless-devs/s -g.

Execute the following command , Check the version and check that it is installed correctly .
The results are as follows , You can see Serverless-Devs Version of the tool .
 Insert picture description here

3. Configure alicloud account information

explain :

This scenario provides free ECS The server , However, the function calculation service used is opened under your account , The following configuration information also needs to configure your account UID、AccessKry ID and AccessKey Secret Information .

Execute the following command , Configure account information .

s config add

Then fill in the following information according to the prompts .

Cloud manufacturers : choice Alibaba Cloud(alibaba).
 Insert picture description here

AccountID: Please view your alicloud primary account on the account security settings page ID.

 Insert picture description here
AccessKeyID and AccessKeySecret: Please check your account number on the security information management page AccessKey ID and AccessKey Secret.

·  If you are using the main account of alicloud , Please in the security prompt pop-up box on the security information management page , Click continue AccessKey.
![ Insert picture description here ](,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dhbmd5aWtlamk=,size_16,color_FFFFFF,t_70)
·  If you are using alicloud RAM Sub user , You need to make sure that your child users have function calculation management rights AliyunFCFullAccess, See for RAM User authorization .
 As shown in the figure below , You can go to the user AccessKey Area to view your AccessKey ID and AccessKey Secret. If your account has not been used AccessKey, Please click create... In the upper right corner AccessKey.
![ Insert picture description here ](,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2dhbmd5aWtlamk=,size_16,color_FFFFFF,t_70)
 After successful configuration , You will receive Configuration successful A reminder of , As shown in the figure below .

 Insert picture description here

4. build Django Blog Blog project

1、 Execute the following command , Initialize a... In the current path Django Blog project .

s init devsapp/django-blog
1)  Enter the project file name django-blog Press enter .

 Insert picture description here

2)  Select the default credentials and press enter .

 Insert picture description here

 The results are as follows . 

 Insert picture description here

2、 take Typecho The project is deployed to the function computing service .

1)  Execute the following command , Enter the project directory .
cd django-blog
2)  Execute the following command , Deployment project .
s deploy

The results are as follows .

 Insert picture description here
3、 Open the virtual desktop browser , Visit the test domain name , View deployed Django Blog The blog system .

 Insert picture description here
Next, you can add some themes and plug-ins to enrich your blog system .

copyright notice
author[Alibaba cloud experience Lab],Please bring the original link to reprint, thank you.

Random recommended