本篇文章給大家分享的是有關Django中怎么接收post前端返回的json格式數(shù)據(jù),小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
post接收字符串
def subscription(request): msg = request.POST.get('msg') # tel_no = request.POST.get('tel_no') # email = request.POST.get('email') # ico_id = request.POST.get('ico_id') data = base64.b64decode(msg) data = data.decode('utf-8') data = json.loads(data) client = pymongo.MongoClient(host = 'localhost',port = 27017) db = client.users my_set = db.user if 'ico_id' not in data.keys(): return HttpResponse(json.dumps({"result_code":1})) result_code = my_set.insert({"tel_no":data.get('tel_no'),"email":data.get('email'),"ico_id":data.get('ico_id'),'date':datetime.datetime.now()}) return HttpResponse(json.dumps({"result_code":0}))
post接收json格式
def selectedico(request): if request.method == 'POST': web_id = json.loads(request.body.decode().replace("'", "\"")).get('id') client = pymongo.MongoClient(host = 'localhost',port = 27017) db = client.webdata my_set = db.webchinadata values = [] #print(web_id) print(request.body.decode()) for val in my_set.find(): # value = value.decode('utf-8') # val = json.loads(value) val["_id"] = str(val["_id"]) val["date"] = str(val["date"]) discount = (''.join(val["discounts"])).split('\n') dis = [x.strip(' ') for x in discount if x != ''] val["discounts"] = dis val["accept_coins"] = val["accept_coins"].split(",") details = (''.join(val["details"])).replace('\n','') val["details"] = details #print(val["_id"]) if val["_id"] == web_id: values.append(val) return HttpResponse(json.dumps(values,ensure_ascii=False),content_type="application/json;charset=utf-8")
以上就是Django中怎么接收post前端返回的json格式數(shù)據(jù),小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學到更多知識。更多詳情敬請關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
當前文章:Django中怎么接收post前端返回的json格式數(shù)據(jù)-創(chuàng)新互聯(lián)
分享鏈接:http://jinyejixie.com/article0/dcghio.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、標簽優(yōu)化、響應式網(wǎng)站、App開發(fā)、企業(yè)網(wǎng)站制作、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容