To use WeChat JS-SDK features (like sharing) in a web application, you must first include the official WeChat JS file and then include the configuration script provided by wechat-django to initialize wx.config with the correct signature and parameters.
1. Include the WeChat JS file
Add the official WeChat JS library to your HTML:
<script src="//res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
2. Include the wechat-django configuration script
You need to load the configuration generated by the package. The jsApiList parameter must include all JS interfaces you intend to use.
If using Django Templates:
Use the wechat_django:jsconfig URL name. Pass the required interfaces via the jsApiList query parameter.
<script src="{% url 'wechat_django:jsconfig' 'debug' %}?jsApiList=onMenuShareTimeline,onMenuShareAppMessage&debug=1"></script>
If NOT using Django Templates (Static/Direct URL):
Use the direct path pattern: /wechat/<yourappname>/wx.config.js. Replace <yourappname> with your actual Django app name.
<script src="/wechat/{{yourappname}}/wx.config.js?jsApiList=onMenuShareTimeline,onMenuShareAppMessage&debug=1"></script>
Parameters
jsApiList: A comma-separated list of the JS interfaces you need (e.g., onMenuShareTimeline,onMenuShareAppMessage).debug: Set to 1 to enable debug mode. This will only function if settings.py has DEBUG = True.
<!-- Example for Django Templates -->
<script src="//res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script src="{% url 'wechat_django:jsconfig' 'debug' %}?jsApiList=onMenuShareTimeline,onMenuShareAppMessage&debug=1"></script>