xadmin无法加载主题的原因是httplib2无法获取到数据,bootswatch那边的服务器反回的状态码为304 一般30几的可能意味着重定向,我 没用这个httplib库,不了解, 我比较倾向requests模块。
环境:django3.1.5 + python3.8.5
这个环境要改很多文件,具体百度
安装xadmin 极简命令 (不适用django3.0及其以上):
pip install https://codeload.github.com/sshwsfc/xadmin/zip/django2 -i https://pypi.douban.com/simple/
- 安装找到文件位置 导入模块
pip install requests
- 找到代码修改如下
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']})
content = requests.get(url="https://bootswatch.com/api/3.json").json()
# watch_themes = eval(context)
# if six.PY3:
# content = content.decode()
watch_themes = 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)
图如下: