xadmin采用源代码的方式引入到项目中
在xadmin使用的过程中,设置“use_bootswatch = True”,企图调出主题菜单,显示更多主题。然而设置了后,发现主题还是默认和bootstrap2,深入跟踪源代码,发现/xadmin/plugins/themes.py下的
block_top_navmenu
当use_bootswatch 为True的时候,就会使用httplib2去
http://bootswatch.com/api/3.json
网址获取主题菜单项。但是使用浏览器打开这个网址,http会被替换成https的。httplib2访问这个https的网址,就会报错。报错信息为:
[SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure
这边使用requests库来替代httplib2.
pip install requests
import requests
# Block Views
def block_top_navmenu(self, context, nodes):
themes = [
{'name': _(u"Default"), 'description': _(u"Default bootstrap theme"), 'css': self.default_theme},
{'name': _(u"Bootstrap2"), 'description': _(u"Bootstrap 2.x theme"), 'css': self.bootstrap2_theme},
]
select_css = context.get('site_theme', self.default_theme)
if self.user_themes:
themes.extend(self.user_themes)
if self.use_bootswatch:
ex_themes = cache.get(THEME_CACHE_KEY)
if ex_themes:
themes.extend(json.loads(ex_themes))
else:
ex_themes = []
try:
flag = False # 假如为True使用原来的代码,假如为Flase,使用requests库来访问
if flag:
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']
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])
except Exception as e:
print(e)
cache.set(THEME_CACHE_KEY, json.dumps(ex_themes), 24 * 3600)
themes.extend(ex_themes)
nodes.append(loader.render_to_string('xadmin/blocks/comm.top.theme.html', {'themes': themes, 'select_css': select_css}))
site.register_plugin(ThemePlugin, BaseAdminView)
原文链接: https://my.oschina.net/u/2396236/blog/1083251
转载from:http://blog.csdn.net/dimples_54/article/details/77963593
相关知识
Responses of terrestrial ecosystem water use efficiency to climate change: a review
Effect of tillage and fertilization on water use efficiency of maize in dryland conditions
While some artisans work with plain sugar,most use colorings for everything from surprisingly realistic flowers to beautiful blown sugar decorations on a holiday
土壤管理实践对土壤磷动态的影响:荟萃分析,Soil Use and Management
Nitrogen Mediates Flowering Time and Nitrogen Use Efficiency via Floral Regulators in Rice==国家水稻数据中心文献数据库
Wheat yield, nutrient use efficiencies and soil nutrient balance under reduced fertilizer rate
浅析当代中国油画中花的运用An analysis of the use of flowers in Contemporary Chinese oil painting.pdf
Effect of fertilizer management on dry matter accumulation, yield and fertilizer use efficiency of rice cultivar 'Huayou
Effect of N fertilization method on rice yield and N, P and K uptake and use efficiency
[Science] 生物固碳:利用能源的又一新途径
原文链接: xadmin的主题use https://m.huajiangbk.com/newsview891139.html
| 上一篇: 幼儿园主题墙面设计:阳光花 | 下一篇: 虎皮兰叶子中间干枯怎么回事 |