xadmin为啥设置了use

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xadmin为啥设置了use相关的知识,希望对你有一定的参考价值。

参考技术A 在xadmin使用的过程中,设置“use_bootswatch = True”,企图调出主题菜单,显示更多主题。然而设置了后,发现主题还是默认和bootstrap2,

解决xadmin下设置“use_bootswatch = True”无效的问题

环境:
python 2.7
django 1.9
xadmin采用源代码的方式引入到项目中

 

1.安装requests

pip install requests


2./xadmin/plugins/themes.py 引入requests

import requests


3.修改block_top_navmenu方法:

    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
                    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]})
                        watch_themes = json.loads(content)[themes]
                    else:
                        content = requests.get("https://bootswatch.com/api/3.json")
                        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}))

参考网址:https://my.oschina.net/u/2396236/blog/1083251

以上是关于xadmin为啥设置了use的主要内容,如果未能解决你的问题,请参考以下文章

解决xadmin下设置“use_bootswatch = True”无效的问题

xadmin的主题use_bootswatch = True”无效解决方法

xadmin下设置“use_bootswatch = True”无效解决方法

xadmin设置

Django xadmin 消息提醒(含demo)

django-xadmin设置全局变量