Python provides custom menu instances for public platforms and python instances.
First, obtain the access_token and save it to the global
def token(requset): url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s' % ( Config.AppID, Config.AppSecret) result = urllib2.urlopen(url).read() Config.access_token = json.loads(result).get('access_token') print 'access_token===%s' % Config.access_token return HttpResponse(result)
Use the access_token obtained above to create a custom form
Def createMenu (request): url = "https://api.weixin.qq.com/cgi-bin/menu/create? Access_token = % s "% Config. access_token data = {"button": [{"name": "", "sub_button": [{"type": "click", "name ": "meitu", "key": "meitu" },{ "type": "view", "name": "featured", "url": "http://m.jb51.net/photos "}, {"type": "view", "name": "Review", "url": "http://m.qzone.com/infocenter? G_f = #2378686916/mine "},{" type ":" view "," name ":" meitu app "," url ":" http://jb51.net/app/app.html "}]}, {"name": "Case study", "sub_button": [{"type": "click", "name": "All style", "key ": "style" },{ "type": "click", "name": "All units", "key": "houseType" },{ "type ": "click", "name": "All area", "key": "area" },{ "type": "view", "name ": "More cases", "url": "http://m.jb51.net/projects"}] },{ "type": "view", "name": "design application", "url ": "http: // Jb51.net/zhuanti/freedesign.jsp? Src = 3 "}]} # data = json. loads (data) # data = urllib. urlencode (data) req = urllib2.Request (url) req. add_header ('content-type', 'application/json') req. add_header ('encoding', 'utf-8') response = urllib2.urlopen (req, json. dumps (data, ensure_ascii = False) result = response. read () return HttpResponse (result)