注:python3和Django2.1环境安装可参考博文《Django基础-安装配置》
xadmin2下载安装
在线安装(建议)
pip install git+git://github.com/sshwsfc/xadmin.git@django2
或
pip install git+git://github.com/sshwsfc/xadmin.git
下载 xadmin2.0 文件并解压
https://github.com/sshwsfc/xadmin
- 1、项目中新建目录 extra_apps (名称可自定义),作为第三方依赖的存放目录
- 2、选中 extra_apps 目录,右击Mark Directory as > Resource Root
环境配置
查看依赖包命令
pip list
确认是否拥有以下几种
django-crispy-forms 1.7.2
django-formtools 2.1
django-import-export 1.2.0
django-reversion 3.0.3
配置项目 setting 新增APP
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'APP.apps.AppConfig',
'xadmin',
'crispy_forms',
'reversion',
]
配置项目 setting 新增搜索目录 extra_apps
STATIC_URL = '/static/'
STATIC_ROOT = 'APP/static'
STATICFILES_DIRS = (
os.path.join(BASE_DIR,"APP/static/html"),
os.path.join(BASE_DIR, 'extra_apps'),)
urls 路由添加
from django.contrib import admin
from django.urls import path,re_path
import xadmin
urlpatterns = [
path('admin/', admin.site.urls),
re_path('xadmin/',xadmin.site.urls),
]
生成数据表
python manage.py makemigrations APP
python manage.py migrate
创建用户用于测试
python manage.py createsuperuser
至此可以访问测试了
http://127.0.0.1/xadmin
常见错误
render() got an unexpected keyword argument 'renderer'
C:\Users\wefbn\AppData\Local\Programs\Python\Python\lib\site-packages\django\forms\boundfield.py in as_widget, line 93
进入xadmin安装路径,编辑C:\Users\administrator\AppData\Local\Programs\Python\Python\Lib\site-packages\django\forms\boundfield.py 第93行注释掉
# renderer=self.form.renderer,
来源:oschina
链接:https://my.oschina.net/u/2924779/blog/3045806