####设置xadmin
- 下载Django-xadmin
- xadmin依赖的库:
django-crispy-forms>=1.6.0
django-import-export>=0.5.1
django-reversion>=2.0.0
django-formtools1.0
future0.15.2
httplib20.9.2
six1.10.0
xlwt
xlsxwriter
2. 将xadmin作为一个app导入Django项目中
3. 注册到seeting.INSTALLED_APPS中(两个字段):
```'xadmin',
'crispy_forms',```
4. 写入项目url:
```import xadmin
url(r'^xadmin/', xadmin.site.urls),```
5. 表迁移和生成:
```makemigrations
migrate
```
6. 创建超级用户:```createsuperuser```
#### 将应用注册到后台:
- 在应用内创建 adminx.py
- 模板:
```
import xadmin
from .models import User
class UserAdmin(object):
#控制显示字段
list_display = ['name', 'age', 'address', 'user_desc']
#添加搜索框
search_fields = ['name']
#添加富文本图片内容显示(需要配置富文本应用)
style_fields = {"user_desc": "ueditor"}
xadmin.site.register(User,UserAdmin)
```
##### 配置富文本图片显示:
- 将DjangoUeditor导入项目
- setting.py:
```
注册'DjangoUeditor'
#配置media的url
MEDIA_URL = "/media/"
#加入到环境变量
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
```
- 配置urls.py
```
from AtguiguShop.settings import MEDIA_ROOT
from django.views.static import serve
url(r'^media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}),
```
- adminx.py
以```style_fields = {"user_desc": "ueditor"}```的形式为某字段配置富文本显示