随笔 - 633,  文章 - 0,  评论 - 13,  阅读 - 48万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

1.注册主题代码:

复制代码
import xadmin
from xadmin import views

class BaseSettings(object):   #全站的配置类, 配置主题
    enable_themes = True  #主题功能,enable_themes=True 表示要使用它的主题功能,xadmin默认是取消掉的,默认只有两个主题
    use_bootswatch = True   #xadmin默认是取消掉的,显示更多主题,可以打开为True,然后会请求https://bootswatch.com/api/3.json,如果请求失败,就只会显示两个默认的
                   #请求的代码为 xadmin 下的plugins下的themes.py文件中 if self.use_bootswatch:(大概69行),会请求https://bootswatch.com/api/3.json加载,加载失败会只显示两个主题
xadmin.site.register(views.BaseAdminView,BaseSetting)
复制代码

 themes.py文件中 if self.use_bootswatch:代码如下:

复制代码
        if self.use_bootswatch:
            ex_themes = cache.get(THEME_CACHE_KEY)
            print("ex_themes:")
            print(ex_themes)
            if ex_themes:
                themes.extend(json.loads(ex_themes))
            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']})
                    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)

                cache.set(THEME_CACHE_KEY, json.dumps(ex_themes), 24 * 3600)
                themes.extend(ex_themes)
复制代码

2.问题出现原因

  正常的话,设置use_bootswatch = True 后,应该会显示很多主题,不止两个,但是当if self.use_bootswatch:后的代码进行https://bootswatch.com/api/3.json请求失败后,就会只显示两个

3.解决方法:

  3.1. 在浏览器中输入“https://bootswatch.com/api/3.json”,得到内容如下:

  

复制代码
{
  "version": "3.4.1",
  "themes": [
    {
      "name": "Cerulean",
      "description": "A calm blue sky",
      "thumbnail": "https://bootswatch.com/3/cerulean/thumbnail.png",
      "preview": "https://bootswatch.com/3/cerulean/",
      "css": "https://bootswatch.com/3/cerulean/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/cerulean/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cerulean/bootstrap.min.css",
      "less": "https://bootswatch.com/3/cerulean/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/cerulean/variables.less",
      "scss": "https://bootswatch.com/3/cerulean/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/cerulean/_variables.scss"
    },
    {
      "name": "Cosmo",
      "description": "An ode to Metro",
      "thumbnail": "https://bootswatch.com/3/cosmo/thumbnail.png",
      "preview": "https://bootswatch.com/3/cosmo/",
      "css": "https://bootswatch.com/3/cosmo/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/cosmo/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cosmo/bootstrap.min.css",
      "less": "https://bootswatch.com/3/cosmo/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/cosmo/variables.less",
      "scss": "https://bootswatch.com/3/cosmo/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/cosmo/_variables.scss"
    },
    {
      "name": "Cyborg",
      "description": "Jet black and electric blue",
      "thumbnail": "https://bootswatch.com/3/cyborg/thumbnail.png",
      "preview": "https://bootswatch.com/3/cyborg/",
      "css": "https://bootswatch.com/3/cyborg/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/cyborg/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cyborg/bootstrap.min.css",
      "less": "https://bootswatch.com/3/cyborg/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/cyborg/variables.less",
      "scss": "https://bootswatch.com/3/cyborg/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/cyborg/_variables.scss"
    },
    {
      "name": "Darkly",
      "description": "Flatly in night mode",
      "thumbnail": "https://bootswatch.com/3/darkly/thumbnail.png",
      "preview": "https://bootswatch.com/3/darkly/",
      "css": "https://bootswatch.com/3/darkly/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/darkly/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/darkly/bootstrap.min.css",
      "less": "https://bootswatch.com/3/darkly/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/darkly/variables.less",
      "scss": "https://bootswatch.com/3/darkly/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/darkly/_variables.scss"
    },
    {
      "name": "Flatly",
      "description": "Flat and modern",
      "thumbnail": "https://bootswatch.com/3/flatly/thumbnail.png",
      "preview": "https://bootswatch.com/3/flatly/",
      "css": "https://bootswatch.com/3/flatly/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/flatly/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css",
      "less": "https://bootswatch.com/3/flatly/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/flatly/variables.less",
      "scss": "https://bootswatch.com/3/flatly/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/flatly/_variables.scss"
    },
    {
      "name": "Journal",
      "description": "Crisp like a new sheet of paper",
      "thumbnail": "https://bootswatch.com/3/journal/thumbnail.png",
      "preview": "https://bootswatch.com/3/journal/",
      "css": "https://bootswatch.com/3/journal/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/journal/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/journal/bootstrap.min.css",
      "less": "https://bootswatch.com/3/journal/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/journal/variables.less",
      "scss": "https://bootswatch.com/3/journal/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/journal/_variables.scss"
    },
    {
      "name": "Lumen",
      "description": "Light and shadow",
      "thumbnail": "https://bootswatch.com/3/lumen/thumbnail.png",
      "preview": "https://bootswatch.com/3/lumen/",
      "css": "https://bootswatch.com/3/lumen/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/lumen/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/lumen/bootstrap.min.css",
      "less": "https://bootswatch.com/3/lumen/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/lumen/variables.less",
      "scss": "https://bootswatch.com/3/lumen/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/lumen/_variables.scss"
    },
    {
      "name": "Paper",
      "description": "Material is the metaphor",
      "thumbnail": "https://bootswatch.com/3/paper/thumbnail.png",
      "preview": "https://bootswatch.com/3/paper/",
      "css": "https://bootswatch.com/3/paper/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/paper/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/paper/bootstrap.min.css",
      "less": "https://bootswatch.com/3/paper/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/paper/variables.less",
      "scss": "https://bootswatch.com/3/paper/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/paper/_variables.scss"
    },
    {
      "name": "Readable",
      "description": "Optimized for legibility",
      "thumbnail": "https://bootswatch.com/3/readable/thumbnail.png",
      "preview": "https://bootswatch.com/3/readable/",
      "css": "https://bootswatch.com/3/readable/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/readable/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/readable/bootstrap.min.css",
      "less": "https://bootswatch.com/3/readable/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/readable/variables.less",
      "scss": "https://bootswatch.com/3/readable/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/readable/_variables.scss"
    },
    {
      "name": "Sandstone",
      "description": "A touch of warmth",
      "thumbnail": "https://bootswatch.com/3/sandstone/thumbnail.png",
      "preview": "https://bootswatch.com/3/sandstone/",
      "css": "https://bootswatch.com/3/sandstone/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/sandstone/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css",
      "less": "https://bootswatch.com/3/sandstone/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/sandstone/variables.less",
      "scss": "https://bootswatch.com/3/sandstone/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/sandstone/_variables.scss"
    },
    {
      "name": "Simplex",
      "description": "Mini and minimalist",
      "thumbnail": "https://bootswatch.com/3/simplex/thumbnail.png",
      "preview": "https://bootswatch.com/3/simplex/",
      "css": "https://bootswatch.com/3/simplex/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/simplex/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/simplex/bootstrap.min.css",
      "less": "https://bootswatch.com/3/simplex/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/simplex/variables.less",
      "scss": "https://bootswatch.com/3/simplex/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/simplex/_variables.scss"
    },
    {
      "name": "Slate",
      "description": "Shades of gunmetal gray",
      "thumbnail": "https://bootswatch.com/3/slate/thumbnail.png",
      "preview": "https://bootswatch.com/3/slate/",
      "css": "https://bootswatch.com/3/slate/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/slate/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/slate/bootstrap.min.css",
      "less": "https://bootswatch.com/3/slate/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/slate/variables.less",
      "scss": "https://bootswatch.com/3/slate/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/slate/_variables.scss"
    },
    {
      "name": "Spacelab",
      "description": "Silvery and sleek",
      "thumbnail": "https://bootswatch.com/3/spacelab/thumbnail.png",
      "preview": "https://bootswatch.com/3/spacelab/",
      "css": "https://bootswatch.com/3/spacelab/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/spacelab/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/spacelab/bootstrap.min.css",
      "less": "https://bootswatch.com/3/spacelab/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/spacelab/variables.less",
      "scss": "https://bootswatch.com/3/spacelab/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/spacelab/_variables.scss"
    },
    {
      "name": "Superhero",
      "description": "The brave and the blue",
      "thumbnail": "https://bootswatch.com/3/superhero/thumbnail.png",
      "preview": "https://bootswatch.com/3/superhero/",
      "css": "https://bootswatch.com/3/superhero/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/superhero/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css",
      "less": "https://bootswatch.com/3/superhero/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/superhero/variables.less",
      "scss": "https://bootswatch.com/3/superhero/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/superhero/_variables.scss"
    },
    {
      "name": "United",
      "description": "Ubuntu orange and unique font",
      "thumbnail": "https://bootswatch.com/3/united/thumbnail.png",
      "preview": "https://bootswatch.com/3/united/",
      "css": "https://bootswatch.com/3/united/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/united/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/united/bootstrap.min.css",
      "less": "https://bootswatch.com/3/united/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/united/variables.less",
      "scss": "https://bootswatch.com/3/united/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/united/_variables.scss"
    },
    {
      "name": "Yeti",
      "description": "A friendly foundation",
      "thumbnail": "https://bootswatch.com/3/yeti/thumbnail.png",
      "preview": "https://bootswatch.com/3/yeti/",
      "css": "https://bootswatch.com/3/yeti/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/yeti/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/yeti/bootstrap.min.css",
      "less": "https://bootswatch.com/3/yeti/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/yeti/variables.less",
      "scss": "https://bootswatch.com/3/yeti/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/yeti/_variables.scss"
    }
  ]
}
复制代码

  将  "themes" 的值 给 user_themes,如下:

复制代码
    user_themes = [
    {
      "name": "Cerulean",
      "description": "A calm blue sky",
      "thumbnail": "https://bootswatch.com/3/cerulean/thumbnail.png",
      "preview": "https://bootswatch.com/3/cerulean/",
      "css": "https://bootswatch.com/3/cerulean/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/cerulean/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cerulean/bootstrap.min.css",
      "less": "https://bootswatch.com/3/cerulean/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/cerulean/variables.less",
      "scss": "https://bootswatch.com/3/cerulean/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/cerulean/_variables.scss"
    },
    {
      "name": "Cosmo",
      "description": "An ode to Metro",
      "thumbnail": "https://bootswatch.com/3/cosmo/thumbnail.png",
      "preview": "https://bootswatch.com/3/cosmo/",
      "css": "https://bootswatch.com/3/cosmo/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/cosmo/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cosmo/bootstrap.min.css",
      "less": "https://bootswatch.com/3/cosmo/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/cosmo/variables.less",
      "scss": "https://bootswatch.com/3/cosmo/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/cosmo/_variables.scss"
    },
    {
      "name": "Cyborg",
      "description": "Jet black and electric blue",
      "thumbnail": "https://bootswatch.com/3/cyborg/thumbnail.png",
      "preview": "https://bootswatch.com/3/cyborg/",
      "css": "https://bootswatch.com/3/cyborg/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/cyborg/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cyborg/bootstrap.min.css",
      "less": "https://bootswatch.com/3/cyborg/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/cyborg/variables.less",
      "scss": "https://bootswatch.com/3/cyborg/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/cyborg/_variables.scss"
    },
    {
      "name": "Darkly",
      "description": "Flatly in night mode",
      "thumbnail": "https://bootswatch.com/3/darkly/thumbnail.png",
      "preview": "https://bootswatch.com/3/darkly/",
      "css": "https://bootswatch.com/3/darkly/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/darkly/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/darkly/bootstrap.min.css",
      "less": "https://bootswatch.com/3/darkly/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/darkly/variables.less",
      "scss": "https://bootswatch.com/3/darkly/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/darkly/_variables.scss"
    },
    {
      "name": "Flatly",
      "description": "Flat and modern",
      "thumbnail": "https://bootswatch.com/3/flatly/thumbnail.png",
      "preview": "https://bootswatch.com/3/flatly/",
      "css": "https://bootswatch.com/3/flatly/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/flatly/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css",
      "less": "https://bootswatch.com/3/flatly/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/flatly/variables.less",
      "scss": "https://bootswatch.com/3/flatly/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/flatly/_variables.scss"
    },
    {
      "name": "Journal",
      "description": "Crisp like a new sheet of paper",
      "thumbnail": "https://bootswatch.com/3/journal/thumbnail.png",
      "preview": "https://bootswatch.com/3/journal/",
      "css": "https://bootswatch.com/3/journal/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/journal/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/journal/bootstrap.min.css",
      "less": "https://bootswatch.com/3/journal/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/journal/variables.less",
      "scss": "https://bootswatch.com/3/journal/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/journal/_variables.scss"
    },
    {
      "name": "Lumen",
      "description": "Light and shadow",
      "thumbnail": "https://bootswatch.com/3/lumen/thumbnail.png",
      "preview": "https://bootswatch.com/3/lumen/",
      "css": "https://bootswatch.com/3/lumen/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/lumen/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/lumen/bootstrap.min.css",
      "less": "https://bootswatch.com/3/lumen/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/lumen/variables.less",
      "scss": "https://bootswatch.com/3/lumen/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/lumen/_variables.scss"
    },
    {
      "name": "Paper",
      "description": "Material is the metaphor",
      "thumbnail": "https://bootswatch.com/3/paper/thumbnail.png",
      "preview": "https://bootswatch.com/3/paper/",
      "css": "https://bootswatch.com/3/paper/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/paper/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/paper/bootstrap.min.css",
      "less": "https://bootswatch.com/3/paper/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/paper/variables.less",
      "scss": "https://bootswatch.com/3/paper/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/paper/_variables.scss"
    },
    {
      "name": "Readable",
      "description": "Optimized for legibility",
      "thumbnail": "https://bootswatch.com/3/readable/thumbnail.png",
      "preview": "https://bootswatch.com/3/readable/",
      "css": "https://bootswatch.com/3/readable/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/readable/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/readable/bootstrap.min.css",
      "less": "https://bootswatch.com/3/readable/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/readable/variables.less",
      "scss": "https://bootswatch.com/3/readable/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/readable/_variables.scss"
    },
    {
      "name": "Sandstone",
      "description": "A touch of warmth",
      "thumbnail": "https://bootswatch.com/3/sandstone/thumbnail.png",
      "preview": "https://bootswatch.com/3/sandstone/",
      "css": "https://bootswatch.com/3/sandstone/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/sandstone/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css",
      "less": "https://bootswatch.com/3/sandstone/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/sandstone/variables.less",
      "scss": "https://bootswatch.com/3/sandstone/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/sandstone/_variables.scss"
    },
    {
      "name": "Simplex",
      "description": "Mini and minimalist",
      "thumbnail": "https://bootswatch.com/3/simplex/thumbnail.png",
      "preview": "https://bootswatch.com/3/simplex/",
      "css": "https://bootswatch.com/3/simplex/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/simplex/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/simplex/bootstrap.min.css",
      "less": "https://bootswatch.com/3/simplex/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/simplex/variables.less",
      "scss": "https://bootswatch.com/3/simplex/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/simplex/_variables.scss"
    },
    {
      "name": "Slate",
      "description": "Shades of gunmetal gray",
      "thumbnail": "https://bootswatch.com/3/slate/thumbnail.png",
      "preview": "https://bootswatch.com/3/slate/",
      "css": "https://bootswatch.com/3/slate/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/slate/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/slate/bootstrap.min.css",
      "less": "https://bootswatch.com/3/slate/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/slate/variables.less",
      "scss": "https://bootswatch.com/3/slate/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/slate/_variables.scss"
    },
    {
      "name": "Spacelab",
      "description": "Silvery and sleek",
      "thumbnail": "https://bootswatch.com/3/spacelab/thumbnail.png",
      "preview": "https://bootswatch.com/3/spacelab/",
      "css": "https://bootswatch.com/3/spacelab/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/spacelab/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/spacelab/bootstrap.min.css",
      "less": "https://bootswatch.com/3/spacelab/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/spacelab/variables.less",
      "scss": "https://bootswatch.com/3/spacelab/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/spacelab/_variables.scss"
    },
    {
      "name": "Superhero",
      "description": "The brave and the blue",
      "thumbnail": "https://bootswatch.com/3/superhero/thumbnail.png",
      "preview": "https://bootswatch.com/3/superhero/",
      "css": "https://bootswatch.com/3/superhero/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/superhero/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css",
      "less": "https://bootswatch.com/3/superhero/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/superhero/variables.less",
      "scss": "https://bootswatch.com/3/superhero/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/superhero/_variables.scss"
    },
    {
      "name": "United",
      "description": "Ubuntu orange and unique font",
      "thumbnail": "https://bootswatch.com/3/united/thumbnail.png",
      "preview": "https://bootswatch.com/3/united/",
      "css": "https://bootswatch.com/3/united/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/united/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/united/bootstrap.min.css",
      "less": "https://bootswatch.com/3/united/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/united/variables.less",
      "scss": "https://bootswatch.com/3/united/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/united/_variables.scss"
    },
    {
      "name": "Yeti",
      "description": "A friendly foundation",
      "thumbnail": "https://bootswatch.com/3/yeti/thumbnail.png",
      "preview": "https://bootswatch.com/3/yeti/",
      "css": "https://bootswatch.com/3/yeti/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/yeti/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/yeti/bootstrap.min.css",
      "less": "https://bootswatch.com/3/yeti/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/yeti/variables.less",
      "scss": "https://bootswatch.com/3/yeti/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/yeti/_variables.scss"
    }
  ]
复制代码

  可以只要name和css两个字段

  3.2. 将use_bootswatch = False,然后赋值user_themes,最终配置如下:

复制代码
import xadmin
from xadmin import views   #导入xadmin中的views,用于和 BaseSettings类绑定


class BaseSettings(object):   #全站的配置类, 配置主题
    enable_themes = True  #主题功能,enable_themes=True 表示要使用它的主题功能,xadmin默认是取消掉的,默认只有两个主题
    use_bootswatch = False   #xadmin默认是取消掉的,显示更多主题,可以打开为True,然后会请求https://bootswatch.com/api/3.json,如果请求失败,就只会显示两个默认的
                             #请求的代码为 xadmin 下的plugins下的themes.py文件中 if self.use_bootswatch:(大概69行),会请求https://bootswatch.com/api/3.json加载,加载失败会只显示两个主题
    user_themes = [
    {
      "name": "Cerulean",
      "description": "A calm blue sky",
      "thumbnail": "https://bootswatch.com/3/cerulean/thumbnail.png",
      "preview": "https://bootswatch.com/3/cerulean/",
      "css": "https://bootswatch.com/3/cerulean/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/cerulean/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cerulean/bootstrap.min.css",
      "less": "https://bootswatch.com/3/cerulean/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/cerulean/variables.less",
      "scss": "https://bootswatch.com/3/cerulean/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/cerulean/_variables.scss"
    },
    {
      "name": "Cosmo",
      "description": "An ode to Metro",
      "thumbnail": "https://bootswatch.com/3/cosmo/thumbnail.png",
      "preview": "https://bootswatch.com/3/cosmo/",
      "css": "https://bootswatch.com/3/cosmo/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/cosmo/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cosmo/bootstrap.min.css",
      "less": "https://bootswatch.com/3/cosmo/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/cosmo/variables.less",
      "scss": "https://bootswatch.com/3/cosmo/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/cosmo/_variables.scss"
    },
    {
      "name": "Cyborg",
      "description": "Jet black and electric blue",
      "thumbnail": "https://bootswatch.com/3/cyborg/thumbnail.png",
      "preview": "https://bootswatch.com/3/cyborg/",
      "css": "https://bootswatch.com/3/cyborg/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/cyborg/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/cyborg/bootstrap.min.css",
      "less": "https://bootswatch.com/3/cyborg/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/cyborg/variables.less",
      "scss": "https://bootswatch.com/3/cyborg/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/cyborg/_variables.scss"
    },
    {
      "name": "Darkly",
      "description": "Flatly in night mode",
      "thumbnail": "https://bootswatch.com/3/darkly/thumbnail.png",
      "preview": "https://bootswatch.com/3/darkly/",
      "css": "https://bootswatch.com/3/darkly/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/darkly/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/darkly/bootstrap.min.css",
      "less": "https://bootswatch.com/3/darkly/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/darkly/variables.less",
      "scss": "https://bootswatch.com/3/darkly/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/darkly/_variables.scss"
    },
    {
      "name": "Flatly",
      "description": "Flat and modern",
      "thumbnail": "https://bootswatch.com/3/flatly/thumbnail.png",
      "preview": "https://bootswatch.com/3/flatly/",
      "css": "https://bootswatch.com/3/flatly/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/flatly/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/flatly/bootstrap.min.css",
      "less": "https://bootswatch.com/3/flatly/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/flatly/variables.less",
      "scss": "https://bootswatch.com/3/flatly/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/flatly/_variables.scss"
    },
    {
      "name": "Journal",
      "description": "Crisp like a new sheet of paper",
      "thumbnail": "https://bootswatch.com/3/journal/thumbnail.png",
      "preview": "https://bootswatch.com/3/journal/",
      "css": "https://bootswatch.com/3/journal/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/journal/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/journal/bootstrap.min.css",
      "less": "https://bootswatch.com/3/journal/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/journal/variables.less",
      "scss": "https://bootswatch.com/3/journal/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/journal/_variables.scss"
    },
    {
      "name": "Lumen",
      "description": "Light and shadow",
      "thumbnail": "https://bootswatch.com/3/lumen/thumbnail.png",
      "preview": "https://bootswatch.com/3/lumen/",
      "css": "https://bootswatch.com/3/lumen/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/lumen/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/lumen/bootstrap.min.css",
      "less": "https://bootswatch.com/3/lumen/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/lumen/variables.less",
      "scss": "https://bootswatch.com/3/lumen/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/lumen/_variables.scss"
    },
    {
      "name": "Paper",
      "description": "Material is the metaphor",
      "thumbnail": "https://bootswatch.com/3/paper/thumbnail.png",
      "preview": "https://bootswatch.com/3/paper/",
      "css": "https://bootswatch.com/3/paper/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/paper/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/paper/bootstrap.min.css",
      "less": "https://bootswatch.com/3/paper/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/paper/variables.less",
      "scss": "https://bootswatch.com/3/paper/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/paper/_variables.scss"
    },
    {
      "name": "Readable",
      "description": "Optimized for legibility",
      "thumbnail": "https://bootswatch.com/3/readable/thumbnail.png",
      "preview": "https://bootswatch.com/3/readable/",
      "css": "https://bootswatch.com/3/readable/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/readable/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/readable/bootstrap.min.css",
      "less": "https://bootswatch.com/3/readable/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/readable/variables.less",
      "scss": "https://bootswatch.com/3/readable/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/readable/_variables.scss"
    },
    {
      "name": "Sandstone",
      "description": "A touch of warmth",
      "thumbnail": "https://bootswatch.com/3/sandstone/thumbnail.png",
      "preview": "https://bootswatch.com/3/sandstone/",
      "css": "https://bootswatch.com/3/sandstone/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/sandstone/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/sandstone/bootstrap.min.css",
      "less": "https://bootswatch.com/3/sandstone/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/sandstone/variables.less",
      "scss": "https://bootswatch.com/3/sandstone/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/sandstone/_variables.scss"
    },
    {
      "name": "Simplex",
      "description": "Mini and minimalist",
      "thumbnail": "https://bootswatch.com/3/simplex/thumbnail.png",
      "preview": "https://bootswatch.com/3/simplex/",
      "css": "https://bootswatch.com/3/simplex/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/simplex/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/simplex/bootstrap.min.css",
      "less": "https://bootswatch.com/3/simplex/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/simplex/variables.less",
      "scss": "https://bootswatch.com/3/simplex/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/simplex/_variables.scss"
    },
    {
      "name": "Slate",
      "description": "Shades of gunmetal gray",
      "thumbnail": "https://bootswatch.com/3/slate/thumbnail.png",
      "preview": "https://bootswatch.com/3/slate/",
      "css": "https://bootswatch.com/3/slate/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/slate/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/slate/bootstrap.min.css",
      "less": "https://bootswatch.com/3/slate/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/slate/variables.less",
      "scss": "https://bootswatch.com/3/slate/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/slate/_variables.scss"
    },
    {
      "name": "Spacelab",
      "description": "Silvery and sleek",
      "thumbnail": "https://bootswatch.com/3/spacelab/thumbnail.png",
      "preview": "https://bootswatch.com/3/spacelab/",
      "css": "https://bootswatch.com/3/spacelab/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/spacelab/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/spacelab/bootstrap.min.css",
      "less": "https://bootswatch.com/3/spacelab/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/spacelab/variables.less",
      "scss": "https://bootswatch.com/3/spacelab/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/spacelab/_variables.scss"
    },
    {
      "name": "Superhero",
      "description": "The brave and the blue",
      "thumbnail": "https://bootswatch.com/3/superhero/thumbnail.png",
      "preview": "https://bootswatch.com/3/superhero/",
      "css": "https://bootswatch.com/3/superhero/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/superhero/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/superhero/bootstrap.min.css",
      "less": "https://bootswatch.com/3/superhero/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/superhero/variables.less",
      "scss": "https://bootswatch.com/3/superhero/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/superhero/_variables.scss"
    },
    {
      "name": "United",
      "description": "Ubuntu orange and unique font",
      "thumbnail": "https://bootswatch.com/3/united/thumbnail.png",
      "preview": "https://bootswatch.com/3/united/",
      "css": "https://bootswatch.com/3/united/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/united/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/united/bootstrap.min.css",
      "less": "https://bootswatch.com/3/united/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/united/variables.less",
      "scss": "https://bootswatch.com/3/united/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/united/_variables.scss"
    },
    {
      "name": "Yeti",
      "description": "A friendly foundation",
      "thumbnail": "https://bootswatch.com/3/yeti/thumbnail.png",
      "preview": "https://bootswatch.com/3/yeti/",
      "css": "https://bootswatch.com/3/yeti/bootstrap.css",
      "cssMin": "https://bootswatch.com/3/yeti/bootstrap.min.css",
      "cssCdn": "https://maxcdn.bootstrapcdn.com/bootswatch/3.3.7/yeti/bootstrap.min.css",
      "less": "https://bootswatch.com/3/yeti/bootswatch.less",
      "lessVariables": "https://bootswatch.com/3/yeti/variables.less",
      "scss": "https://bootswatch.com/3/yeti/_bootswatch.scss",
      "scssVariables": "https://bootswatch.com/3/yeti/_variables.scss"
    }
  ]   #将use_bootswatch 设置为False ,不进行https://bootswatch.com/api/3.json请求加载,而是只使用user_themes,缺点就是不能动态加载,优点就是不会丢失

xadmin.site.register(views.BaseAdminView, BaseSettings)   #注册BaseSettings
复制代码

 

posted on   大话人生  阅读(406)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示