# 19、利用 django-simpleui 模板在管理后台添加自定义的菜单和自定义的页面、设置访问权限

利用 django-simpleui 模板在管理后台添加自定义的菜单和自定义的页面、设置访问权限

* settings.py

```python
SIMPLEUI_CONFIG = {
    'system_keep': True,
    'menu_display': ['Cloudflare', '用户扩展', '权限认证', ],
    'dynamic': True,
    'menus': [{
        # 'app': 'DrfApi',
        'name': 'Cloudflare',
        'icon': 'fa fa-file',
        'models': [
            {
                'name': 'CF账号',
                'icon': 'far fa-surprise',
                'url': 'DrfApi/cloudflare/'
            },
            {
                'name': '内网穿透',
                'url': 'https://www.wezoz.com',
                'icon': 'fab fa-github'
            },
            {
                'name': '自定义页面',         # 新加的 url 页面
                'url': 'testhtml/',
                'icon': 'fab fa-github'
            }
        ]
    },

        {
        'app': 'test_jwt',
        'name': '用户扩展',
        'icon': 'fas fa-user-shield',
        'models': [
                {
                    'name': '用户',
                    'icon': 'fa fa-user',
                    'url': 'test_jwt/userinfo/'
                }
        ]
    },

        {
        'app': 'auth',
        'name': '权限认证',
        'icon': 'fas fa-user-shield',
        'models': [
            {
                'name': '组',
                'icon': 'fa fa-user',
                'url': 'auth/group/'
            }
        ]
    },


    ]
}
```

* views.py

```python
from django.shortcuts import render
from django.contrib.admin.views.decorators import staff_member_required


def testhtml(request):
    '''自定义的页面'''
    return render(request, 'test/test.html')

testhtml = staff_member_required(testhtml)
```

* testhtml

```html
 {% extends 'admin/base_site.html' %} 

 {% block content %} 
     what are you name 
 {% endblock %}
```

* urls.py

```python
from dtheme import views

urlpatterns = [
    # 第一个就是我们自己新增的url路径
    # 这个路由一定要添加在admin.site.urls的前面，因为不然的话，它会先去admin.site.urls里面去匹配，造成混乱或报错。
    re_path(r'^admin/testhtml/', views.testhtml),
    re_path(r'^admin/', admin.site.urls),
    re_path(r'^api/user/', include('duser.urls')),
    re_path(r'^api/post/', include('dpost.urls')),
    re_path(r'^api/theme/', include('dtheme.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
```

![](/files/OL8IHAFtdwf1b6vSSCNV)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://close.gitbook.io/yun-wei-bi-ji/python/django/19-li-yong-djangosimpleui-mu-ban-zai-guan-li-hou-tai-tian-jia-zi-ding-yi-de-cai-dan-he-zi-ding-yi-de.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
