我尝试将Django Administration的模板添加到具有职员权限的简单应用视图中。我在视图的顶部添加了{% extends "admin/base_site.html" %}
,但标题的某些部分缺失了。
正常管理标题:
使用管理模板测试视图:
程序my_app / urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('test/', views.test, name='test')
]
程序my_app / views.py:
from django.contrib.admin.views.decorators import staff_member_required
from django.shortcuts import render
@staff_member_required
def test(request):
return render(request, 'test.html')
程序my_app /模板/的test.html:
{% extends "admin/base_site.html" %}
{% block content %}
<p>Test</p>
{% endblock %}
MY_PROJECT / urls.py:
from django.contrib import admin
from django.urls import include, path
admin.autodiscover()
admin.site.site_header = "Test 1"
admin.site.index_title = "Test 2"
admin.site.site_title = "Test 3"
urlpatterns = [
path('my_app/', include('my_proj.my_app.urls')),
path('', admin.site.urls),
]
谢谢!