from xadmin import views
import xadmin
class BaseSetting(object):
enable_themes=True
use_bootswatch=True
xadmin.site.register(views.BaseAdminView,BaseSetting)
复制一下代码到相应位置
try:
flag = False # 假如为True使用原来的代码,假如为Flase,使用requests库来访问
if flag:
h = httplib2.Http()
resp, content = h.request("http://bootswatch.com/api/3.json", ‘GET‘, ‘‘,
headers={"Accept": "application/json",
"User-Agent": self.request.META[‘HTTP_USER_AGENT‘]})
if six.PY3:
content = content.decode()
watch_themes = json.loads(content)[‘themes‘]
else:
content = requests.get("https://bootswatch.com/api/3.json")
if six.PY3:
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])
# 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‘]})
# 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])
except Exception as e:
print(e)