Python server programming: using django-jet for background management

WBOY
Release: 2023-06-18 08:04:00
Original
1436 people have browsed it

In the modern Internet era, server programming is an essential skill. Among them, Python has become one of the most widely used programming languages, and there are more and more server programming tools for Python. One of the recommended tools is django-jet.

django-jet is a modern and concise style background management interface framework based on the Django framework and is widely used in Python server-side development. Django-jet provides a unified backend management interface, including routing, forms, lists, search, filtering, paging, uploading and other functions, which is very suitable for internal information management of enterprises.

So, how to use django-jet for background management? After actual testing, we will introduce it to you in detail below.

First, you need to install django-jet. It can be installed from the command line via pip: pip install django-jet. In addition, you also need to add "jet" and "jet.dashboard" to INSTALLED_APPS in the settings.py file.

Next, routing configuration needs to be done in the urls.py file. Specifically:

(1) Import jet and admin in the DJANGO_PROJECT/urls.py file.

from django.urls import path, include
from django.contrib import admin
from jet.dashboard.dashboard_modules import google_analytics_views
from jet.dashboard.dashboard_modules import yandex_metrika_views
from jet.dashboard.dashboard_modules import memcache_views
from jet.dashboard.dashboard_modules import generator_views
import jet.urls

urlpatterns = [
    path('django_admin/', admin.site.urls),
    path('jet/', include('jet.urls', 'jet')),
    path('jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')),
]
Copy after login

(2) Modify the urls.py file of the application and link to the above configuration.

from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('jet/', include('jet.urls', 'jet')),
    path('jet/dashboard/', include('jet.dashboard.urls', 'jet-dashboard')),
]
Copy after login

(3) Add some necessary configuration items in the settings.py file.

INSTALLED_APPS = [
    # ... some other apps
    'jet',
    'jet.dashboard',
    'django.contrib.admin',
]

JET_DEFAULT_THEME = 'default'
JET_SIDE_MENU_COMPACT = True
JET_CHANGE_FORM_SIBLING_LINKS = True
JET_INDEX_DASHBOARD = 'dashboard.CustomIndexDashboard'

TEMPLATES = [
    {
        # ... some other settings
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),
            os.path.join(BASE_DIR, 'templates/jet'),
            os.path.join(BASE_DIR, 'templates/jet.dashboard'),
        ],
        'APP_DIRS': True,
        # ... some other settings
    },
]
Copy after login

What needs to be noted here is:

a. JET_DEFAULT_THEME: Set the theme color of the django-jet background management interface, which can be set to "default", "green", "purple", etc.

b. JET_SIDE_MENU_COMPACT: Set whether the side menu should be compressed.

c. JET_CHANGE_FORM_SIBLING_LINKS: Set whether to enable django-jet's changing links.

d. JET_INDEX_DASHBOARD: Set the default django-jet background management interface.

(4) Configure dashboard.CustomIndexDashboard

First, add a new class in the application's models.py, then add a method in this class, and register it with a decorator, as follows Display:

from jet.dashboard.dashboard import Dashboard, AppIndexDashboard
from django.utils.translation import ugettext_lazy as _

class CustomIndexDashboard(Dashboard):
    columns = 3

    def init_with_context(self, context):
        self.available_children.append(
            AppIndexDashboard(
                _('Applications'),
                column=1,
                children=[{
                    'app_label': app_label
                } for app_label in [
                    'auth', 'personal', 'hello_django_starter'
                ]],
                deletable=False,
            ),
        )
Copy after login

Among them, the init_with_context method is used to initialize the background management interface, and you can adjust the page information by yourself. Here we simply set up 3 columns of content, including applications, tasks, subscription management, etc.

Finally, we need to run python manage.py runserver as before to start the web server, and enter http://127.0.0.1:8000/jet/ in the browser to see the implemented background Management interface.

To summarize, it is very simple to use django-jet to build a backend management interface. It only takes a few steps to complete and is one of the recommended tools for Python server programming. If you need to use the backend management interface when developing enterprise information management systems, data visualization and other applications, here is a feasible solution for your reference.

The above is the detailed content of Python server programming: using django-jet for background management. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template