From ea53bfc1b215dd2d01a615634be91e5266f8e855 Mon Sep 17 00:00:00 2001 From: AllenZhao <1048141587@qq.com> Date: Wed, 28 Nov 2018 15:38:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3xadmin=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xadmin/plugins/themes.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/xadmin/plugins/themes.py b/xadmin/plugins/themes.py index 9210beb8e..d83dd9cc3 100644 --- a/xadmin/plugins/themes.py +++ b/xadmin/plugins/themes.py @@ -1,6 +1,6 @@ #coding:utf-8 from __future__ import print_function -import httplib2 +import requests from django.template import loader from django.core.cache import cache from django.utils import six @@ -71,16 +71,13 @@ def block_top_navmenu(self, context, nodes): else: ex_themes = [] try: - h = httplib2.Http() - resp, content = h.request("https://bootswatch.com/api/3.json", 'GET', '', - headers={"Accept": "application/json", "User-Agent": self.request.META['HTTP_USER_AGENT']}) + headers = {"Accept": "application/json", "User-Agent": self.request.META['HTTP_USER_AGENT']} + content = requests.get("https://bootswatch.com/api/3.json", headers=headers) if six.PY3: - content = content.decode() - watch_themes = json.loads(content)['themes'] - ex_themes.extend([ - {'name': t['name'], 'description': t['description'], - 'css': t['cssMin'], 'thumbnail': t['thumbnail']} - for t in watch_themes]) + content = content.text.decode() + watch_themes = json.loads(content.text)['themes'] + ex_themes.extend([{'name': t['name'], 'description': t['description'], 'css': t['cssMin'], + 'thumbnail': t['thumbnail']} for t in watch_themes]) except Exception as e: print(e)