Django接收post前端返回的json格式數(shù)據(jù)代碼實(shí)現(xiàn)
更新時(shí)間:2019年07月31日 14:07:23 作者:_Haimei
這篇文章主要介紹了Django接收post前端返回的json格式數(shù)據(jù)代碼實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
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")
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python實(shí)現(xiàn)的矩陣類實(shí)例
這篇文章主要介紹了Python實(shí)現(xiàn)的矩陣類,結(jié)合完整實(shí)例形式分析了Python矩陣的定義、計(jì)算、轉(zhuǎn)換等相關(guān)操作技巧,需要的朋友可以參考下2017-08-08Python MySQLdb 使用utf-8 編碼插入中文數(shù)據(jù)問(wèn)題
這篇文章主要介紹了Python MySQLdb 使用utf-8 編碼插入中文數(shù)據(jù)問(wèn)題,需要的朋友可以參考下2018-03-03Python通過(guò)kerberos安全認(rèn)證操作kafka方式
這篇文章主要介紹了Python通過(guò)kerberos安全認(rèn)證操作kafka方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-06-06Python打包后的exe還原成.py的實(shí)現(xiàn)步驟
本文主要介紹了Python打包后的exe還原成.py的實(shí)現(xiàn)步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02