xadmin 安装

环境(一定要一样)

  • Python 3.6.2
  • Django 2.0

安装

  1. pip install django==2.0, 指定特定的版本
  2. pip install https://codeload.github.com/sshwsfc/xadmin/zip/django2, 从官方的 github 上下载 django2 分支的包, 也可通将该包下载下来再使用 pip 安装, 但是不推荐使用 pip 安装, 建议将 xadmin 放到 libs 下
  3. 目录结构

.
├── __pycache__
│   └── manage.cpython-36.pyc
├── apps
│   ├── __pycache__
│   ├── food
│   │   ├── __init__.py
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-36.pyc
│   │   │   ├── admin.cpython-36.pyc
│   │   │   ├── adminx.cpython-36.pyc
│   │   │   ├── apps.cpython-36.pyc
│   │   │   └── models.cpython-36.pyc
│   │   ├── admin.py
│   │   ├── adminx.py
│   │   ├── apps.py
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   ├── __init__.py
│   │   │   └── __pycache__
│   │   │   ├── 0001_initial.cpython-36.pyc
│   │   │   └── __init__.cpython-36.pyc
│   │   ├── models.py
│   │   ├── tests.py
│   │   └── views.py
│   └── user
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── admin.cpython-36.pyc
│   │   ├── adminx.cpython-36.pyc
│   │   ├── apps.cpython-36.pyc
│   │   └── models.cpython-36.pyc
│   ├── admin.py
│   ├── adminx.py
│   ├── apps.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── 0002_auto_20190621_1320.py
│   │   ├── __init__.py
│   │   └── __pycache__
│   │   ├── 0001_initial.cpython-36.pyc
│   │   ├── 0002_auto_20190621_1320.cpython-36.pyc
│   │   └── __init__.cpython-36.pyc
│   ├── models.py
│   ├── tests.py
│   └── views.py
├── libs
├── manage.py
├── media
├── static
├── templates
├── utils
│   └── __init__.py
└── xadmintest
├── __init__.py
├── __pycache__
│   ├── __init__.cpython-36.pyc
│   ├── settings.cpython-36.pyc
│   ├── urls.cpython-36.pyc
│   └── wsgi.cpython-36.pyc
├── settings.py
├── urls.py
└── wsgi.py

配置

  1. 所有的 app 都在 apps 目录中, libs 存放第三方拷贝过来的库, 所以需要在 settings.py 中添加如下, 在 INSTALL_APPS 时可以直接写 app 名(推荐这样写, 不这样写可能会有错误)

sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))
sys.path.insert(0, os.path.join(BASE_DIR, 'libs'))
  1. 在 settings.py 中的 INSTALL_APPS 添加 xadmin, reversion, crispy_forms

  2. 将 settings.py 中的语言设置成使其支持中文


    LANGUAGE_CODE = 'zh-hans'
    TIME_ZONE = 'Asia/Shanghai'
    USE_I18N = True
    USE_L10N = True
    USE_TZ = False # 设置为 False 则使用本地时间,否则会使用国际时间
  3. 如果使用 django 自带的用户模块, 还要在 settings.py 中添加 AUTH_USER_MODEL = 'user.UserProfile' 来说重载系统的 User, 其中 user 是 app 名, UserProfile 是该 app 下 models.py 文件中定义的继承了 django.contrib.auth.model.AbstractUser 的类的类名

  4. 将 url.py 中的 url 改为 path('xadmin/', xadmin.site.urls)

  5. 为每一个 model 配置一个 admin, 不再使用 admin.py 而是使用 adminx.py, 在 adminx.py 中使用, 和 admin.py 用法差不多, 我们只需要提供 list_display, search_fields, list_filter


class UserAdmin(object): list_display = ['name', 'birthday', 'gender']
search_fields = ['name', 'birthday', 'gender']
list_filter = ['name', 'birthday', 'gender'] # xadmin.site.register(UserProfile, UserAdmin), model 不能为 User, 因为内部已经使用了
# 注意, 在扩展 Django 自带的 User 模块时, 需要设置 null=True, blank=True, 否则在之后的 ./manage.py createsuperuser 中会失败
  1. xadmin 还有一些全局配置, 一般就在继承了 AbstractUser 的 models 中定义

class BaseSetting(object): enable_themes = True
use_bootswatch = True class GlobalSettings(object): site_title = '我的管理后台'
site_footer = '我的后台' xadmin.site.register(views.BaseAdminView, BaseSetting)
xadmin.site.register(views.CommAdminView, GlobalSettings)
  1. 配置后台 app 显示中文, 在每一个 app 下的 __init__.py 中添加

default_app_config = 'user.apps.UserConfig' # 这里的 user 为 app 名, UserConfig 为 apps.py 中的类的类名, 要在 UserConfig 中填写 name 和 verbose_name 两个属性, 其中 verbose_name 为中文
  1. 迁移数据库

./manage.py makemigrations && ./manage.py migrate
  1. 创建管理员用户

./manage.py createsuperuser
  1. 如果要在模型中使用富文本编辑器, 需要拷贝 DjangoUeditor(是百度的 Django 项目) 到 libs 中, 在 xadmin 中的 plugins 中添加 ueditor.py 的插件, 内容如下, 这是从一个人的博客derek中得到的, 在 model 中, 如果想要使用富文本域, 需要导入 UEditor 中的 UEditorField, 使用也在下面

# libs/xadmin/plugins/ueditor.py
#!/usr/bin/env python
# -*- coding: utf-8 -*- import xadmin
from xadmin.views import BaseAdminPlugin, CreateAdminView, ModelFormAdminView, UpdateAdminView
from DjangoUeditor.models import UEditorField
from DjangoUeditor.widgets import UEditorWidget
from django.conf import settings class XadminUEditorWidget(UEditorWidget): def __init__(self, **kwargs):
self.ueditor_options = kwargs
self.Media.js = None
super(XadminUEditorWidget,self).__init__(kwargs) class UeditorPlugin(BaseAdminPlugin): def get_field_style(self, attrs, db_field, style, **kwargs):
if style == 'ueditor':
if isinstance(db_field, UEditorField):
widget = db_field.formfield().widget
param = {}
param.update(widget.ueditor_settings)
param.update(widget.attrs)
return {'widget':XadminUEditorWidget(**param)}
return attrs def block_extrahead(self, context, nodes):
print(settings.STATIC_URL)
js = '<script type="text/javascript" src="%s"></script>' % (settings.STATIC_URL + "ueditor/ueditor.config.js")
js += '<script type="text/javascript" src="%s"></script>' % (settings.STATIC_URL + "ueditor/ueditor.all.min.js")
nodes.append(js) xadmin.site.register_plugin(UeditorPlugin, UpdateAdminView)
xadmin.site.register_plugin(UeditorPlugin, CreateAdminView) # apps/yourmodel/models.py class Food(models.Model): name = models.CharField(max_length=30, verbose_name='食品名称')
price = models.FloatField(default=0, verbose_name='价格')
brief = models.TextField(max_length=500, verbose_name='简介')
description = UEditorField(verbose_name='内容', imagePath='food/images/', filePath='food/files/', default='')
supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE) class Meta:
verbose_name = '食品'
verbose_name_plural = verbose_name def __str__(self):
return self.name

xadmin 安装的更多相关文章

  1. django xadmin 安装和使用

    官方文档: http://xadmin.readthedocs.io/en/docs-chinese/ 版本:django1.9 pip安装部署 pip install xadmin settings ...

  2. xadmin 安装详解

    1.安装必要的包 django>=1.9.0 django-crispy-forms>=1.6.0 django-import-export>=0.5.1 django-revers ...

  3. 个人博客开发之 xadmin 安装

    项目源码下载:http://download.vhosts.cn xadmin 下载地址:https://github.com/sshwsfc/xadmin或 https://github.com/s ...

  4. xadmin安装

    1 安装满足django2的版本 pip3 install https://codeload.github.com/sshwsfc/xadmin/zip/django2 2 urls.py里面增加路由 ...

  5. django xadmin安装

    安装方式一: 下载xadmin源码文件,下载之后,解压缩,将解压目录中的xadmin文件夹拷贝到项目项目文件中.下载地址:https://codeload.github.com/sshwsfc/xad ...

  6. xadmin安装和配置

    1.在虚拟环境pip install xadmin 2.安装完成之后在settings.py的install app里面添加xadmin和crispy_forms 3.在主项目url里面把原来的adm ...

  7. 第三百七十九节,Django+Xadmin打造上线标准的在线教育平台—xadmin的安装

    第三百七十九节,Django+Xadmin打造上线标准的在线教育平台—xadmin的安装 xadmin介绍 xadmin是基于Django的admin开发的更完善的后台管理系统,页面基于Bootstr ...

  8. 安装xadmin后台管理插件

    django自带的admin后台管理功能太少.使用国人开发的xadmin后台,使用pip install xadmin安装在线包时,会出错,其中的README.rst是utf8格式,我们win7系统默 ...

  9. django安装使用xadmin

    Xadmin介绍 直接替换掉Django自带的admin系统,并提供了很多有用的东西:完全的可扩展的插件支持,基于Twitter Bootstrap的漂亮UI. 完全替代Django admin 支持 ...

随机推荐

  1. java 数据结构(九):Collection子接口:List接口

    1. 存储的数据特点:存储序的.可重复的数据. 2. 常用方法:(记住)增:add(Object obj)删:remove(int index) / remove(Object obj)改:set(i ...

  2. python 装饰器(七):装饰器实例(四)类装饰器装饰类以及类方法

    类装饰器装饰类方法 不带参数 from functools import wraps import types class CatchException: def __init__(self,orig ...

  3. Python函数02/函数的动态参数/函数的注释/名称空间/函数的嵌套/global以及nolocal的用法

    Python函数02/函数的动态参数/函数的注释/名称空间/函数的嵌套/global以及nolocal的用法 目录 Python函数02/函数的动态参数/函数的注释/名称空间/函数的嵌套/global ...

  4. hihoCoder 1052 基因工程 最详细的解题报告

    题目来源:基因工程 解题思路:假设基因序列长度为N,则需要计算基因序列前K个和后K个相同所需要的最少改变次数sum. 假设基因序列为 ATACGTCT (即M=8),K=6:interval=M-K= ...

  5. (五)学习了解OrchardCore笔记——灵魂中间件ModularTenantContainerMiddleware的第一行②模块的功能部分

    在(三)的时候已经说到模块集合用ForEachAsync的扩展方法分配多个任务,把每个modules的ManifestInfo分析出来的功能加入ConcurrentDictionary.我们先看看这个 ...

  6. 【C#】NET截屏网页,生成网页快照开发——IECapt、CutyCapt

    软件介绍 IECapt.CutyCapt 生成网页快照 http://iecapt.sourceforge.net/ http://cutycapt.sourceforge.net/ ### 操作代码 ...

  7. TLV通信协议

    基础 TLV协议是BER编码的一种,全称是Tag.length.value.该协议简单高效,能适用于各种通信场景,且具有良好的可扩展性.TLV协议的基本格式如下: 其中,Tag占2个字节,是报文的唯一 ...

  8. Shell基本语法---for语句

    for语句 格式 ()for 变量名 in 值1 值2 值3 do 执行动作 done ()for 变量名 in `命令` do 执行动作 done ()for (( 条件 )) do 执行动作 do ...

  9. 图文详解压力测试工具JMeter的安装与使用

    压力测试是目前大型网站系统的设计和开发中不可或缺的环节,通常会和容量预估等工作结合在一起,穿插在系统开发的不同方案.压力测试可以帮助我们及时发现系统的性能短板和瓶颈问题,在这个基础在上再进行针对性的性 ...

  10. vue传参方式

    //query传参,使用name跳转   this.$router.push({       name:'second',       query: {         queryId:'201808 ...