The design URL is distributed by the way Xadmin_demo

Source: Internet
Author: User

Such as

Urlpatterns = [
URL (r ' ^xadmin/', ([
URL (r ' ^add/$ ', Views.add)
URL (r ' ^delete/$ ', views.delete)
], None,none)),
This completes the first level distribution

Then make a self-designed URL
Need 3 sheets, additions and deletions, 12 URLs
Such as
127.0.0.1:8000/xadmin/app01/add/
127.0.0.1:8000/xadmin/app01/delete/


Edit in urls.py

def list_view (Request):
Return HttpResponse (' Userindex ')
def add_view (Request):
Return HttpResponse (' User_add ')
def change_view (request, ID):
Return HttpResponse (' User_change ')
def delete_view (request, ID):
Return HttpResponse (' User_delete ')

Def has_urls ():
temp = []
Temp.append (URL (r ' ^$ ', List_view))
Temp.append (URL (r ' ^add/$ ', Add_view))
Temp.append (url (r ' ^ (\d+)/change/$ ', Change_view))
Temp.append (url (r ' ^ (\d+)/delete/$ ', Delete_view))
Print (temp)
Return Temp
Def get_urls ():
Print (Admin.site._registry)
temp = []
For Model,admin_class_obj in Admin.site._registry.items ():
App_name = Model._meta.app_label
Model_name = Model._meta.model_name
Print (App_name,model_name)
Temp.append (URL (r ' ^{0}/{1}/'. Format (app_name,model_name), (Has_urls (), None,none)),)
Return Temp
Urlpatterns = [
Path (' admin/', admin.site.urls),
URL (r ' ^xadmin/', (Get_urls (), None,none)),]

settings.py
Set up
Installed_apps = [
' App01.apps.App01Config ',

' App02.apps.App02Config ',
]

admin.py under the APP01 project
From Django.contrib Import admin
From APP01 import Models
# Register your models here.
Admin.site.register (models. Book)
Admin.site.register (models. Publish)

models.py under the APP01 project


admin.py under the APP02 project
From Django.contrib Import admin
From APP02 import Models
# Register your models here.
Admin.site.register (models. Order)

models.py under the APP01 project
From django.db import Models
Class Order (models. Model):
title = models. Charfield (MAX_LENGTH=32)
def __str__ (self):
Return Self.title



Design URL Xadmin_demo by distribution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.