django Xadmin替换admin
django-Xadmin替换admin
1、下载:
下载地址:https://github.com/sshwsfc/xadmin/tree/django2
2、安装
用pip 安装下载的包
sudo pip3 install xadmin~=2.0
或打开项目路径(如图:forum项目路径):
3.配置setting.py
INSTALLED_APPS = [ ... 'xadmin', ... ]
4.更改app下的admin.py
import xadmin #用户表 class UserAdmin: list_display =['username','password','nickname','phone','birthday','mail','head_img'] fields = ('username','password','nickname','phone','birthday','mail','head_img') search_fields = ['username'] save_on_top = True xadmin.site.register(User, UserAdmin) #地址表 class AddressAdmin: list_display =['address'] fields =('address',) save_on_top = True xadmin.site.register(Address,AddressAdmin)
配置url(将原本指向admin的url改为xadmin):
import xadmin from .custom_site import custom_site urlpatterns = [ path(r'xadmin/', xadmin.site.urls), # path('admin/', custom_site.urls), path('index/',include('blog.urls')), ]
5.配置数据迁移和超级用户,启动服务:
pyhton3 manage.py createsuperuser
python3 manage.py makemigrations
...... migrate
...... runserver
127.0.0.1:8000/xadmin
python