Road to WeChat Mini Program Development (11) Calculator Project Construction (centos8)
pip install django
django-admin startproject weixintest
cd weixintest
python manage.py startapp CalculateApi
calculator/settings.py
weixintest/urls.py
weixintest/CalculateApi/urls.py
weixintest/CalculateApi/views.py (processing function, eval, interface function of the called calculator)
Run the project locally, run through
the public network,
and then set the setting.py
Then you can directly access the public network ip!
WeChat Developer Tools->Settings->Project Settings->Check the options below
Create a new project
index. wxml
<view class="container">
<input type="text" class="input" bindinput='input'/>
<button bindtap="calculate">cal</button>
<view>{
{ result }}</view>
</view>
index.wxss
.input {
border: 1px solid black;
margin-bottom: 5px;
}
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
})
}
})
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.