日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

xadmin引入样式无效

發布時間:2025/7/14 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 xadmin引入样式无效 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

當使用下面方式引入xadmin樣式的時候發現并沒有效果:

file:adminx.py

xadmin
xadmin?views

BaseSetting():
????enable_themes?=?use_bootswatch?=?Some?Codes...
xadmin.site.register(views.CommAdminViewGlobalSettings)

file:__init__.py

default_app_config?=?"users.apps.UsersConfig"

錯誤原因:

當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.

在xadmin的源碼目錄下修改xadmin\plugins\themes.py:

#coding:utf-8
from __future__ import print_function
import httplib2
from django.template import loader
from django.core.cache import cache
from django.utils import six
from django.utils.translation import ugettext as _
from xadmin.sites import site
from xadmin.models import UserSettings
from xadmin.views import BaseAdminPlugin, BaseAdminView
from xadmin.util import static, json
import six
if six.PY2:
? ?import urllib
else:
? ?import urllib.parse
import requests
THEME_CACHE_KEY = 'xadmin_themes'


class ThemePlugin(BaseAdminPlugin):

? ?enable_themes = False
? ?# {'name': 'Blank Theme', 'description': '...', 'css': 'http://...', 'thumbnail': '...'}
? ?user_themes = None
? ?use_bootswatch = False
? ?default_theme = static('xadmin/css/themes/bootstrap-xadmin.css')
? ?bootstrap2_theme = static('xadmin/css/themes/bootstrap-theme.css')

? ?def init_request(self, *args, **kwargs):
? ? ? ?return self.enable_themes

? ?def _get_theme(self):
? ? ? ?if self.user:
? ? ? ? ? ?try:
? ? ? ? ? ? ? ?return UserSettings.objects.get(user=self.user, key="site-theme").value
? ? ? ? ? ?except Exception:
? ? ? ? ? ? ? ?pass
? ? ? ?if '_theme' in self.request.COOKIES:
? ? ? ? ? ?if six.PY2:
? ? ? ? ? ? ? ?func = urllib.unquote
? ? ? ? ? ?else:
? ? ? ? ? ? ? ?func = urllib.parse.unquote
? ? ? ? ? ?return func(self.request.COOKIES['_theme'])
? ? ? ?return self.default_theme

? ?def get_context(self, context):
? ? ? ?context['site_theme'] = self._get_theme()
? ? ? ?return context

? ?# Media
? ?def get_media(self, media):
? ? ? ?return media + self.vendor('jquery-ui-effect.js', 'xadmin.plugin.themes.js')

? ?# 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:
? ? ? ? ? ? ? ? ? ?# 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])
? ? ? ? ? ? ? ? ? ?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])
? ? ? ? ? ? ? ?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://blog.51cto.com/xvjunjie/2084672

總結

以上是生活随笔為你收集整理的xadmin引入样式无效的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。