The Road to WeChat Mini Program Development (11) The first calculator project for WeChat Mini Program (centos8)

Road to WeChat Mini Program Development (11) Calculator Project Construction (centos8)

pip install django

Insert picture description here

django-admin startproject weixintest 

Insert picture description here

cd weixintest
python manage.py startapp CalculateApi

Insert picture description here
calculator/settings.py Insert picture description here
Insert picture description here
weixintest/urls.py
Insert picture description here
weixintest/CalculateApi/urls.py
Insert picture description here
weixintest/CalculateApi/views.py (processing function, eval, interface function of the called calculator)
Insert picture description here

Run the project locally, run through
Insert picture description here
Insert picture description here
the public network,
and then set the setting.py
Insert picture description here

Insert picture description here
Then you can directly access the public network ip!
Insert picture description here
WeChat Developer Tools->Settings->Project Settings->Check the options below
Insert picture description here

Create a new project
Insert picture description here
index. wxml

<view class="container">
  <input type="text" class="input" bindinput='input'/>
  <button bindtap="calculate">cal</button>
  <view>{
   
   { result }}</view>
</view>

Insert picture description here
index.wxss

.input {
    
    
  border: 1px solid black;
  margin-bottom: 5px;
}

Insert picture description here

index.js

const app = getApp()
 
Page({
    
    
  data: {
    
    
    result: "暂无结果",
    formula: ''
  },
  //事件处理函数
  calculate: function () {
    
    
    wx.request({
    
    
      url: 'http://47.97.231.88:8000/calculate',
      data: {
    
    
        formula: this.data.formula
      },
      success: res => {
    
    
        if (res.statusCode == 200) {
    
    
          this.setData({
    
    
            result: res.data
          })
        }
      }
    })
  },
  input: function (e) {
    
    
    this.setData({
    
    
      formula: e.detail.value
    })
  }
})

Insert picture description here
You can run through the project.
However, generally the server is started with a stable web container, and basically does not use manage.py to start the project.

Guess you like

Origin blog.csdn.net/xulei1132562/article/details/113731235