Build a WeChat Public Account Backend with Python/Django: Step‑by‑Step Guide
This guide walks you through creating a WeChat public‑account subscription service using Python and Django, covering environment setup on CentOS, installing dependencies, configuring the wechat‑python‑sdk, defining URL routes and views, and handling common pitfalls such as external access, encoding issues, and port conflicts.
0x00 Background and Introduction
Apply for a WeChat public platform subscription account, connect the backend to a server, verify the server address, implement simple business logic, and respond differently based on the type of user message.
0x01 Language and Framework
Language: Python
Framework: Django
Development package: wechat-python-sdk
GitHub source code: https://github.com/PorridgeEater/WeChat
0x02 Reference Documentation
WeChat public platform development docs: http://mp.weixin.qq.com/wiki/home/index.html
SDK documentation: http://wechat-python-sdk.com/
0x03 Server Configuration
System: CentOS
Configuration steps:
Update the system
Install Python dependencies
Install Python and pip and update
Install Django framework
Install wechat-python-sdk package
Create a Django project
Add URL rules (urls.py)
Write view logic (views.py)
Run Django app on port 80
0x04 WeChat Backend Configuration
Record APPID and APPSecret in the conf attribute of views.py Fill in server configuration
Ensure the URL ends with a trailing slash, otherwise Django reports a POST URL error
Set a custom token in the conf attribute of views.py Set a custom EncodingAESKey in the conf attribute of
views.py0x05 Pitfalls Encountered
After runserver, local access works but external access fails
Bind IP to 0.0.0.0 for public listening
Chinese input does not receive a response
After import os, set encoding to utf8 Port number is already in use
Run ps aux | grep manage and kill the corresponding process
0x06 Afterword
The system can recognize different message types and reply accordingly.
The code’s functionality still needs improvement, and its structure and logic could be clearer.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
