1,xadmin下载: https://github.com/sshwsfc/xadmin/tree/django2(记得要直接下载zip)
2,解压后进入文件夹然后执行
pip install -r requirements.txt
3,然后在项目的根目录创建一个文件夹为:extra_apps,将下载的好的文件中的xadmin文件夹拷贝到extra_apps目录中如下:
4,通过pycharm 选中extra_apps文件夹点击鼠标右键选中菜单mark directory as 选择 sources root就可以变成上面的蓝色文件夹目录就可以了。
5,修改settings.py文件:
(1)添加头文件import sys
(2)在BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))函数下添加:
sys.path.insert(0,os.path.join(BASE_DIR, 'extra_apps'))
(3)在INSTALLED_APPS = []里面插入
'xadmin',
'crispy_forms',
#'reversion',
6,在urls.py里面添加xadmin:
(1)引入头文件import xadmin
(2)注释path('admin/', admin.site.urls),
添加:
path('xadmin/', xadmin.site.urls),
7,登陆:
http://127.0.0.1:8000/xadmin/
8,这个版本有一个bug不能删除数据
在:xadmin\plugins\actions.py下修改
if django_version > (2, 0):
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(queryset, self.opts, self.admin_site)
else:
using = router.db_for_write(self.model)
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
queryset, self.opts, self.user, self.admin_site, using)
if else逻辑颠倒一下就好:
if django_version > (2, 0):
using = router.db_for_write(self.model)
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
queryset, self.opts, self.user, self.admin_site, using)
else:
deletable_objects, model_count, perms_needed, protected = get_deleted_objects(
queryset, self.opts, self.admin_site)
下一篇:没废话保证绝对可行教程(3.1)Django+RestFramework+Xadmin开发之:添加数据以及基本配置:https://www.jianshu.com/p/749a439246bc