Skip to content

Commit

Permalink
添加success_msg
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer121121 committed Jan 8, 2019
1 parent 134a4e8 commit ee0831f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion server/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@
matplotlib.use('agg')
import matplotlib.pyplot as plt

def success_msg(msg_detail=None):
""""
构造一个用于返回页面成功的消息
"""
r={'result':'successs'}

if msg_detail:
r['detail']=msg_detail
else:
r['detail']={}

return r

def json_response(msg, ensure_ascii=False):
"""
给django的JsonResponse增加中文编码支持
:param ensure_ascii:
:param msg:
:return:
"""
dumps_params = {'ensure_ascii': ensure_ascii}
return JsonResponse(msg, json_dumps_params=dumps_params)

def Perter(request):
query = request.GET.get("q")
Expand Down Expand Up @@ -112,7 +135,7 @@ def sort_img(qf, ql, qc, gf, gl, gc):
ax.set_title('%d' % (i + 1), color='red')
imgs.append(img_path)
print(img_path)
return JsonResponse({'result': result})
return json_response(success_msg(imgs))
except RuntimeError:
for i in range(10):
img_path = image_datasets.imgs[index[i]]
Expand Down

0 comments on commit ee0831f

Please sign in to comment.