Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the implementation methods of Python as the Mini Program backend?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what are the implementation methods of Python as a Mini Program backend", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the implementation methods of Python as a Mini Program backend?"

Method 1. Cloud hosting of Wechat

Advantages: no need to purchase servers, no need for domain name registration, billing by usage, DevOps automation, security authentication, suitable for people with no OPS experience.

Disadvantages: the cost of this must be slightly higher than the cost of self-built servers. Just like the same model, an automatic car is more expensive than a manual car.

Cloud hosting is a Docker container. You only need to set up a warehouse. Any one of github, gitlab, or gitee can build a warehouse, write Dockerfile, and upload it to cloud hosting. Cloud hosting will automatically build container images and run them. The way you run containers can be customized. After the deployment, we will get a default domain address, which is the entrance to the service provided by the service. You can call and access it according to the normal service, or you can bind your own domain name.

In Mini Program, you can access the container service as follows:

/ / confirm that wx.cloud.init initialization environment has been called in onLaunch (any environment can be filled in blank) const res = await wx.cloud.callContainer ({config: {env: 'fill in cloud environment ID', / / Wechat cloud hosted environment ID}, path:' / xxx', / / enter business custom path and parameters, root directory It is / method: 'POST', / / according to your own business development, select the corresponding method header: {' XmurWXmurServicial: 'xxx', / / xxx. Enter the service name (Wechat Cloud hosting-Service Management-Service list-Service name). In the above practice, the demo} / / other parameters are the same as wx.request}). Console.log (res)

With the container, the backend can use any programming language, depending on what you are good at, Python is absolutely no problem, and the official Django template, one-click deployment.

Method 2. Transfer the cloud function of Wechat

Advantages: there is no need for domain name filing, there is a certain amount of free.

Cons: configure the server yourself

The so-called cloud function is the Node.js function that runs on Tencent Cloud. It has only computing logic and can seamlessly access the cloud database for data access.

The Mini Program client calls the cloud function as follows:

Wx.cloud.callFunction (name of cloud function to be called name: 'dailyexam', / / event parameter passed to the cloud function data: {x: 1, y: 2,}}) .then (res = > {/ / output: res.result = 3}) .catch (err = > {/ / handle error})

The Node.js function is actually an asynchronous javascript function. In the cloud function, we can request services on the self-built server, so that the domain name does not need to be licensed. For example, in the following code, the domain name somenzz.cn is not licensed.

The cloud function calls the self-built API service as follows:

The free quota is usually very small, the number of database reads per day cannot exceed 500, and the number of writes cannot exceed 300.

Because of self-built services, you can naturally develop with Python.

Method 3: build your own server and record your domain name

Advantages: save money, the larger the number of visitors, the more money.

Disadvantages: need to record the domain name.

Instead of using cloud functions and cloud hosting, you can only use the wx.request function on Mini Program to request self-built services:

Wx.request ({url: 'example.php', / / is only an example, not the real interface address data: {x:', y:'}, header: {'content-type':' application/json' / / default}, success (res) {console.log (res.data)}})

The wx.request function is limited, as follows:

Usually you need a domestic server, and then record the domain name, and filing, usually dissuade a large number of developers.

Because of the self-built server, of course you can develop it with Python.

At this point, I believe you have a deeper understanding of "what are the implementation methods of Python as a Mini Program backend?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report