程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Bid farewell to monotony and transform the Django background home page - use the adminlte component

編輯:Python

Preface

I made a Django Project , In order to make the management background more beautiful , I am right. Django( It should be SimpleUI Of ) default Admin The home page of the backstage is transformed , See this article for details : Project completion - be based on Django3.x edition - Summary of development and deployment

The previous two articles about Django3.x The development and deployment summary articles are all about databases 、 Interface 、 In terms of performance , I am interested in the transformation of the backstage home page when I see a friend's message , So write an article to introduce ~

analysis

The transformation is based on my customized DjangoStarter Development templates , The code in this article will be submitted to Github, Project address :https://github.com/Deali-Axy/DjangoStarter

DjangoStarter Of Admin Used SimpleUI, This is a base Vue、ElementUI Of Admin The theme , Use ElementUI Of tab Component implements the function of multi label , The component itself supports custom home pages , So my idea is to use Django Of Template Write a new page , Configure the route and replace it SimpleUI The default home page for .

The default home page looks like this , It's a bit monotonous

That's what happened after the transformation

well , It's better than before , Rich in content ~

Next, we will implement the transformation of the home page step by step .

rely on

There are many background templates on the Internet , Domestic products include ElementUI、AntDesign these , It's all very good , But it should look good CSS( I'm sorry I don't know much )

So I set my sights on foreign open source components , among AdminLTE It's very good , In my most familiar Bootstrap On this basis , Good looking and easy to use ~

So let's get started

The dependencies used in this page are as follows

  • at present AdminLTE The version is 3.2, be based on Bootstrap4.6
  • The chart uses chart.js, edition 3.8
  • Icon use fontawesome, Use free 6.0 edition

Direct copy package.json Dependent part of :

"dependencies": {
"@fortawesome/fontawesome-free": "^6.0.0",
"admin-lte": "3.2",
"bootstrap": "^4.6.1",
"chart.js": "^3.8.0",
"jquery": "^3.6.0",
}

Copy and save directly , then yarn Command installation depends on ~

PS: Recommended yarn management npm package , It can also be used directly npm

modify Gulp Mission

About the Django Use and manage front-end resources in , Please refer to this article for details :Django Project introduction NPM and gulp Manage front-end resources

// Use npm Download the front-end package 
const libs = [
{name: "admin-lte", dist: "./node_modules/admin-lte/dist/**/*.*"},
{name: "chart.js", dist: "./node_modules/chart.js/dist/**/*.*"},
{name: "jquery", dist: "./node_modules/jquery/dist/**/*.*"},
{name: "bootstrap", dist: "./node_modules/bootstrap/dist/**/*.*"},
]; // Use npm Downloaded front-end components , Custom storage location
const customLibs = [
{name: 'font-awesome', dist: './node_modules/@fortawesome/fontawesome-free/**/*.*'},
]

After saving, execute in the project root directory gulp move that will do ~

Start writing pages

We are templates/admin New under the directory extend_home.html

I will not paste the specific code , It has been uploaded to github Yes , You can see here :https://github.com/Deali-Axy/DjangoStarter/blob/master/templates/admin/extend_home.html

Chart the pie chart I made with fake data , The data looks like this

let exampleData = [
{label: 'a', value: 10},
{label: 'b', value: 10},
{label: 'c', value: 10},
{label: 'd', value: 10},
{label: 'e', value: 10},
{label: 'f', value: 10},
]

The text of news and shortcut is Django Self contained random text generation label

{% lorem 6 w random %}

See the official documents for specific usage :https://docs.djangoproject.com/zh-hans/4.0/ref/templates/builtins/#lorem

PS: All the contents of this page are false data , In actual use, you can use context Pass in data or request interfaces to fill in real data ~

Save after writing the web page template

Next, configure the routing

Write about the View

I put this page on DjangoStarter Default App in

edit apps/core/views.py file

Add a function

# Expand admin Home page , Beautify the backstage 
def extend_admin_home(request):
return render(request, 'admin/extend_home.html')

Configure the routing

urlpatterns = [
# ...
path('admin_home', views.extend_admin_home),
]

To configure SimpleUI Home page

edit config/settings.py

stay SimpleUI Add this line of code to the configuration area

SIMPLEUI_HOME_PAGE = f'/{URL_PREFIX}core/admin_home'

PS: because DjangoStarter Add a URL Prefix function , So we need to URL_PREFIX close

Get it done

That's it , The specific code is quite long , You can see GitHub project :https://github.com/Deali-Axy/DjangoStarter

Students who don't want to follow the steps step by step can try mine DjangoStarter Template ha , It's all integrated , Open the box ~

PS: The next article introduces some development experience of displaying large screens

Say goodbye to monotony ,Django Background homepage transformation - Use AdminLTE More articles on components

  1. Use the front-end background management template library admin-lte( turn )

    Use the front-end background management template library admin-lte Use the front-end background management template library admin-lte install Set up the environment install install admin-lte, You can install it in the following ways , The picture below is GitHub in admin-lte The home page of ...

  2. The front desk homepage is set up 、 Design of the interface of the background home page rotation chart 、 Detailed explanation of cross domain problems 、 The front and rear ends are interconnected 、 Back end custom configuration 、git A preliminary introduction to the software

    Summary of today's content Front desk home page Background home page rotation diagram interface Detailed explanation of cross domain problems Connect the front and rear ends Back end custom configuration git Introduction and installation Detailed content 1. Front desk home page Homeviwe.vue <template> <di ...

  3. python Operations and development ( nineteen )----Django Background form validation 、session、cookie、model operation

    Content catalog : Django Background form validation CSRF The encrypted session.cookie model Database operation Django backstage Form Form validation Django in Form Generally speaking, there are 2 Kind of function : 1. Used for user submission ...

  4. Django Background settings -- Problems encountered and solutions

    1. How does the background manage models New Django The project will automatically reference admin application , You can create a new background by createsuperuser Command to create the background admin Super administrator , The first problem I encountered , It's like this ...

  5. Django The background supports Chinese methods

    A problem we have today ,mark once : django The background can support Chinese interface , At the beginning, I was obsessed with settings.py in LANGUAGE_CODE = 'en-us' Medium 'en-us' What to change .zh-c ...

  6. Powerful Django Background management

    Django  backstage django We just need to add less code in the background , You can achieve powerful functions . And background related files : Every app Medium  admin.py  Files are related to the background The following example is an example of adding blog posts in the background : Create a new one name ...

  7. django Background import excel file

    1.django How to upload from the background excel Medium batch parsing data From you to django Background imported excel Medium batch parsing data , For example , Let's carry back the batch import svn Historical data format hypothesis excel Table has 4 Column , Each column is ...

  8. django Background access is the same name The name of the data

    django Background access is the same name Named post data html: <form method="post"> <input type="text" n ...

  9. 1.1 、Django backstage

    Django backstage And background related files : Every app Medium admin.py Files are related to the background . One , Create a new one The name is HelloDjango Project django-admin.py startproject ...

  10. jquery ajax Submit form Forms as well as django Backstage acceptance

    HTML <form id="project_file_upload" enctype="multipart/form-data" > <di ...

Random recommendation

  1. nyoj_95_ The question of mode _map practice

    The question of mode The time limit :3000 ms  |  Memory limit :65535 KB difficulty :3   describe The so-called mode , That is, for a given object containing N Multiple sets of elements , Each element in S The most frequent occurrence of the element is the multiplicity of the element , Multiple sets S heavy ...

  2. JAVA Thread lock lock Next Condition Advanced use - Multiple Condition Integrated use of

    import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.uti ...

  3. node.js NPM Use

    n=NPM It's a Node Package management and distribution tools , It has become unofficial Node modular ( package ) Standards for . With NPM, You can quickly find the package to be used by a specific service , Download . Install and manage installed packages .npms install : download npm Source ...

  4. sql cascading deletion

    original text :sql cascading deletion function : When deleting the main table , Automatically delete the secondary table ( Foreign key constraints ) Corresponding content Delete the row containing the primary key value , This value is referenced by foreign key columns in existing rows of other tables . In cascade deletion , Also delete all rows whose foreign key values refer to the deleted primary key values . Such as : ...

  5. 2017 Many schools 10 site HDU 6181 Two Paths A short circuit

    Topic link :http://acm.hdu.edu.cn/showproblem.php?pid=6181 The question : Give a picture , Find the secondary short circuit . solution : My previous template cannot solve this problem , It is the case that the shortest and secondary short circuits are equal , Prove ...

  6. establish maven project pom.xml The first line is wrong

    It has been created several times before maven project , It is also the first line reporting an error , Right click the item to force the update maven It seems to have been solved , This time, it seems that this method doesn't work , I gave a bunch of English mistakes and couldn't understand them , Fortunately, I saw a passer-by on the Internet , root ...

  7. c# Empty the text file

    FileStream fs = new FileStream(@"C:\log.txt", FileMode.Truncate, FileAccess.ReadWrite); fs ...

  8. [C#][Report]Cry

    This article is from :https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downl ...

  9. [Unity3D] 01 - Try Unity3D

    01. Move and Rotate Standard global coordinate system Keyboard using UnityEngine; using System.Collections; public class NewBe ...

  10. Soft work &#183; Homework 11 - Alpha Be wise after the event ( The team )

    Soft work · Homework 11 - Alpha Be wise after the event ( The team ) Team leader, this assignment link Modern software engineering project Postmortem Ideas and goals 1. What's the problem with our software ? Is it clearly defined ? For typical users and fields ...


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved