From 624e7bcb1dc420f207d905027bcd5fb4103b135d Mon Sep 17 00:00:00 2001 From: wuyue Date: Sun, 1 Jul 2018 19:47:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0django-suit=E4=BD=9C=E4=B8=BA?= =?UTF-8?q?admin=E5=90=8E=E5=8F=B0ui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rest_backend/settings/base.py | 6 ++--- rest_backend/urls.py | 5 ++-- rest_backend/utils/suit.py | 32 +++++++++++++++++++++++ templates/admin/base_site.html | 46 ++++++++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 5 deletions(-) create mode 100644 rest_backend/utils/suit.py create mode 100644 templates/admin/base_site.html diff --git a/rest_backend/settings/base.py b/rest_backend/settings/base.py index ec58c6a..ff003f4 100644 --- a/rest_backend/settings/base.py +++ b/rest_backend/settings/base.py @@ -29,6 +29,7 @@ # Application definition INSTALLED_APPS = [ + 'rest_backend.utils.suit.SuitConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -66,13 +67,12 @@ AUTH_USER_MODEL = 'accounts.User' # session过期时间设置 -SESSION_COOKIE_AGE = 60*30 - +SESSION_COOKIE_AGE = 60 * 30 TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ diff --git a/rest_backend/urls.py b/rest_backend/urls.py index 513225c..e690741 100644 --- a/rest_backend/urls.py +++ b/rest_backend/urls.py @@ -20,8 +20,9 @@ urlpatterns = [ path('admin/', admin.site.urls), - path('', RedirectView.as_view(url='/api-docs')), - path('', include('rest_backend.libs.backend.urls')) + path('', RedirectView.as_view(url='/admin/')), + path('', include('rest_framework.urls', namespace='rest_framework')), + path('api/', include('rest_backend.libs.backend.urls', namespace='api')) ] if settings.DEBUG: diff --git a/rest_backend/utils/suit.py b/rest_backend/utils/suit.py new file mode 100644 index 0000000..e1a7a82 --- /dev/null +++ b/rest_backend/utils/suit.py @@ -0,0 +1,32 @@ +#! /usr/bin/env python +# -*- coding: utf-8 -*- +""" +@author: wuyue +@contact: wuyue92tree@163.com +@software: PyCharm +@file: suit.py +@create at: 2018-04-29 11:58 + +这一行开始写关于本文件的说明与解释 +""" + +from django.contrib import admin +from suit.apps import DjangoSuitConfig +from suit.menu import ParentItem, ChildItem + +admin.AdminSite.site_header = 'rest_backend后台管理' + + +class SuitConfig(DjangoSuitConfig): + layout = 'vertical' + menu = ( + ParentItem('认证和授权', children=[ + ChildItem(model='accounts.user'), + ChildItem(model='auth.group'), + ], icon='fa fa-users'), + ParentItem('设置', children=[ + # ChildItem('修改密码', url='admin:password_change'), + ChildItem('API接口文档', url='/api/docs', target_blank=True), + + ], align_right=True, icon='fa fa-cog'), + ) diff --git a/templates/admin/base_site.html b/templates/admin/base_site.html new file mode 100644 index 0000000..f93cd9d --- /dev/null +++ b/templates/admin/base_site.html @@ -0,0 +1,46 @@ +{% extends 'admin/base.html' %} +{% load suit_tags admin_static %} +{% block footer %} + {% if not is_popup %} +