Customizing the Django Panel: A Step-By-Step Guide

DDD
发布: 2024-09-19 06:30:03
原创
407 人浏览过

In this guide I'll walk you through how to modify and extend Django default admin panel/interface, making it more user-friendly.

1. Set up the Project:

Start by creating a brand new project and app in Django

django-admin startproject myprojectname
cd myprojectname
python manage.py startapp developerscommunity
登录后复制

** Note**
Do not forgot to add your app ti the INSTALLED_APPS in settings.py

2. Run migrations:

python manage.py makemigrations
python manage.py migrate
登录后复制

3. Resgister Models in Admin Panel:

 Register of models is compulsory to see it in django admin 
 interface

  from django.contrib import admin
  from .models import DevCommunity

 admin.site.register(DevCommunity)
登录后复制

Above Steps will lead you to Django Admin Panel Now comes the customization part

4. Customize the Admin Panel:

class CustomAdminSite(admin.AdminSite):

will appear at the top-left corner

site_header = "Dev Admin"

will show in the browser tab

site_title = Developer Admin Portal

will be displayed on the admin home page.

index_title = "Welcome to Developer Community"

custom_admin_site = CustomAdminSite(name="dev_admin")

  #All code at one place
  class CustomAdminSite(admin.AdminSite):
     site_header = "Dev  Admin"
     site_title = Developer Admin Portal
     index_title = "Welcome to Developer Community"

  custom_admin_site = CustomAdminSite(name="dev_admin")
登录后复制

5. To register:

  #Finally register
  custom_admin_site.register(DevCommunity)
登录后复制

Customizing the Django Panel: A Step-By-Step Guide

以上是Customizing the Django Panel: A Step-By-Step Guide的详细内容。更多信息请关注PHP中文网其他相关文章!

来源:dev.to
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!