我很高兴以前曾经问过类似的问题,但是看了之后,我似乎仍然无法解决我的问题。
根据文档,我具有以下文件:
views.py
from django.shortcuts import render
# Create your views here.
def base(request):
articles = 'articles'
dboard = 'dashboard'
pages = {'dboard':dboard, 'Articles':articles}
return render(request, 'collatedata/base.html', pages)
def dash(request):
return render(request, 'collatedata/dash.html')
collatedata / urls.py:
urlpatterns = [
path('', views.dash, name='dash'),
]
主要urls.py:
urlpatterns = [
path('', include('collatedata.urls')),
path('admin/', admin.site.urls),
]
base.html:
...
<li class="nav-item">
<a href="#" class="nav-link text-white p-3 mb-2">
<i class="fas fa-home text-light fa-lg mr-3"></i>
{{ dboard }}
</a>
</li>
...
dash.html
{% extends "./base.html" %}
但是,输出不会读取{{dboard}}
因此返回此:
<li class="nav-item">
<a href="#" class="nav-link text-white p-3 mb-2">
<i class="fas fa-home text-light fa-lg mr-3"></i>
</a>
</li>
与扩展base.html有关吗?