解决django默认的admin后台默认只能显示一个字段以及admin后台借助bootstrap进行美化

models.py

from django.db import models
# 用户表
class userinfo(models.Model):
    user_name =models.CharField(max_length=32,primary_key=True)
    user_pwd=models.CharField(max_length=32)
    def __str__(self):
        return self.user_name
#上传文件表
class files(models.Model):
    files_id=models.AutoField(primary_key=True)
    files_name=models.FileField(upload_to='media')
    files_user=models.ForeignKey(userinfo,on_delete=models.CASCADE)

admin.py

from django.contrib import admin

from app01.models import userinfo,files
class Files(admin.ModelAdmin):
    list_display = ('files_id','files_name','files_user')
admin.site.register(userinfo)
admin.site.register(files,Files)
# Register your models here.

美化:

在终端导包

pip install django-admin-bootstrapped

在setting中添加站点

INSTALLED_APPS = (
    'django_admin_bootstrapped',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'app01',

)

 

上一篇:Linux超级干货-安装Django与注意事项


下一篇:Django配置Bootstrap, js