使用django-suit为django 1.7 admin后台添加模板

yipeiwu_com6年前Python基础

django-grappelli里面使用inline似乎有点儿问题,换一个皮:

django-suit是2scoops推荐的第二个admin skin.
Supports: Django 1.4-1.7. Python: 2.6-3.
本文的环境是django 1.7.1

django-suit官网
安装指导链接
设置攻略

翻译搬运如下:

安装

复制代码 代码如下:

pip install django-suit

# settings.py
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS as TCP

TEMPLATE_CONTEXT_PROCESSORS = TCP + (
'django.core.context_processors.request',
)

终端

复制代码 代码如下:

python manage.py makemigrations
python manage.py migrate
python manage.py collectstatic

恭喜!基本安装已经完成!

官方攻略还有很多详细的设置,我发现这个插件不只是为了后台服务的,也附赠了许多form widget,在前台也可以善加利用:
举例如下:

datetime widget

复制代码 代码如下:

SuitDateWidget, SuitTimeWidget and SuitSplitDateTimeWidget extends original admin widgets by adding some additional output styling only. Widgets still uses same original JavaScript for calendar and time. You can see example in Demo app: User changeform:

from django.forms import ModelForm
from suit.widgets import SuitDateWidget, SuitTimeWidget, SuitSplitDateTimeWidget

class UserChangeForm(UserChangeForm):
    class Meta:
        model = User
        widgets = {
            'last_login': SuitSplitDateTimeWidget,
            'date_joined': SuitSplitDateTimeWidget,
        }

以上内容大部分精简至官方攻略,给需要的小伙伴们参考下吧

相关文章

python基础教程之面向对象的一些概念

Python使用类(class)和对象(object),进行面向对象(object-oriented programming,简称OOP)的编程。 面向对象的最主要目的是提高程序的重复使...

浅析python3字符串格式化format()函数的简单用法

 format()函数 """ 测试 format()函数 """ def testFormat(): # format()函数中有几个元素,前面格式化的字符串中就要有...

在Python中处理日期和时间的基本知识点整理汇总

在Python中处理日期和时间的基本知识点整理汇总

 Python程序可以处理多种方式的日期和时间。日期格式之间的转换是一种常见计算机的杂活。 Python的时间和日历模块,能帮助处理日期和时间。 Tick是什么? 时间...

python3.6+django2.0开发一套学员管理系统

1.在pycharm中新建project demo1 添加app01 点击create按钮完成新建 2.在demo项目目录下新建目录static,并在settings.py中追加代码:...

python 随机生成10位数密码的实现代码

随机生成10位数密码,字母和数字组合 import string >>> import random >>> pwd = "" >>&...