一、先確認admin該有的都有
1.urls.py
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),]
2.seetings.py
INSTALLED_APPS = [
'django.contrib.admin',]
二、從app裏面寫好自定義內容
1.app裏面的urls.py寫好,這個簡單不寫了
2.app裏面的視圖函數寫好,這個也簡單
3.用不到數據模型就不用在models.py裏面定義了
4.app裏面的admin.py裏面註冊上準備好的東西,重要
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
# Register your models here.
class LogSearch(type):
class Meta:
verbose_name = '日誌查詢'
model_name = 'LogSearch'
app_label = 'common'
abstract = False
swapped = False
app_config = False
verbose_name_plural = verbose_name
object_name = 'LogSearch'
_meta = Meta
@admin.register(LogSearch)
class LogSearchAdmin(admin.ModelAdmin):
def changelist_view(self, request, extra_content=None):
from views import log_index
return log_index(request)
5.app裏面的templates裏面寫好自定義的頁面
基本上就能實現在Django自帶的admin裏面加頁面的需求了,數據庫表不用動,admin加點東西挺方便
參考:
https://www.cnblogs.com/AcAc-t/p/django_template_admin_site_model_python.html
http://www.cnblogs.com/AcAc-t/p/django_template_admin_site_model_python_1.html