Giter Club home page Giter Club logo

wxcloudrun-django's Introduction

wxcloudrun-django

GitHub license GitHub package.json dependency version (prod)

微信云托管 python Django 框架模版,实现简单的计数器读写接口,使用云托管 MySQL 读写、记录计数值。

快速开始

前往 微信云托管快速开始页面,选择相应语言的模板,根据引导完成部署。

本地调试

下载代码在本地调试,请参考微信云托管本地调试指南

实时开发

代码变动时,不需要重新构建和启动容器,即可查看变动后的效果。请参考微信云托管实时开发指南

Dockerfile最佳实践

请参考如何提高项目构建效率

目录结构说明

.
├── Dockerfile                  dockerfile
├── README.md                   README.md文件
├── container.config.json       模板部署「服务设置」初始化配置(二开请忽略)
├── manage.py                   django项目管理文件 与项目进行交互的命令行工具集的入口
├── requirements.txt            依赖包文件
└── wxcloudrun                  app目录
    ├── __init__.py             python项目必带  模块化**
    ├── apps.py                 自动生成文件apps.py
    ├── asgi.py                 自动生成文件asgi.py, 异步服务网关接口
    ├── migrations              数据移植(迁移)模块
    ├── models.py               数据模块
    ├── settings.py             项目的总配置文件  里面包含数据库 web应用 日志等各种配置
    ├── templates               模版目录,包含主页index.html文件
    ├── urls.py                 URL配置文件  Django项目中所有地址中(页面)都需要我们自己去配置其URL
    ├── views.py                执行响应的代码所在模块  代码逻辑处理主要地点  项目大部分代码在此编写
    └── wsgi.py                 自动生成文件wsgi.py, Web服务网关接口

服务 API 文档

GET /api/count

获取当前计数

请求参数

响应结果

  • code:错误码
  • data:当前计数值
响应结果示例
{
  "code": 0,
  "data": 42
}

调用示例

curl https://<云托管服务域名>/api/count

POST /api/count

更新计数,自增或者清零

请求参数

  • actionstring 类型,枚举值
    • 等于 "inc" 时,表示计数加一
    • 等于 "clear" 时,表示计数重置(清零)
请求参数示例
{
  "action": "inc"
}

响应结果

  • code:错误码
  • data:当前计数值
响应结果示例
{
  "code": 0,
  "data": 42
}

调用示例

curl -X POST -H 'content-type: application/json' -d '{"action": "inc"}' https://<云托管服务域名>/api/count

使用注意

如果不是通过微信云托管控制台部署模板代码,而是自行复制/下载模板代码后,手动新建一个服务并部署,需要在「服务设置」中补全以下环境变量,才可正常使用,否则会引发无法连接数据库,进而导致部署失败。

  • MYSQL_ADDRESS
  • MYSQL_PASSWORD
  • MYSQL_USERNAME 以上三个变量的值请按实际情况填写。如果使用云托管内MySQL,可以在控制台MySQL页面获取相关信息。

License

MIT

wxcloudrun-django's People

Contributors

aaronlee0817 avatar cubelrti avatar fisher1006 avatar maple-mxf avatar rangangwei avatar sijingzhangzsj avatar starkwang avatar woodenstone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wxcloudrun-django's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.