Django项目的引导模板支持
django-bootstrap4-nav的Python项目详细描述
创建这个库是为了让django使用一些通用的bootstrap4模板。这个库使用基本 django-bootstrap4的功能。我使用它来匹配模板与我的django_materialize_nav库。在
设置
安装库。在
# project/settings.pyINSTALLED_APPS=["bootstrap4_nav",...]
设置上下文处理器
Bootstrap4_nav附带了一个上下文处理器,可以使用一些设置来更改默认的基本样式。在
^{pr2}$获取视图的标准上下文的另一种方法
# views.pyfrombootstrap4_nav.context_processorsimportget_contextdefshow_page(request):# Get the context with the style settingscontext=get_context(site_name='demo',title='Basic Content')context["object"]="MyObject"returnrender(request,"my_page.html",context)
风格
基本模板可以通过扩展materialize base nav来使用。在
{% extends "bootstrap4_nav/base.html" %} {% block nav_items %} <liclass="navbar-item{% if title == 'Page1' %} active{% endif %}"><aclass="nav-link"href="/">Page1</a></li><liclass="navbar-item{% if title == 'Page2' %} active{% endif %}"><aclass="nav-link"href="/">Page2</a></li><liclass="navbar-item{% if title == 'Page3' %} active{% endif %}"><aclass="nav-link"href="/">Page3</a></li> {% endblock %} {% block contents %} <div><p>My Content goes here</p></div> {% endblock %}
样式控制
Bootstrap4_nav附带了几个样式选项,这些选项在下面列出的模板上下文变量中使用。在
- BOOTSTRAP4_SITE_NAME
- BOOTSTRAP4_TITLE
如果执行了Setup Context Processors步骤,则可以修改多个设置来更改默认样式。 这是手动提供所有模板上下文变量的替代方法。在
# settings.pyBOOTSTRAP4_SITE_NAME=None# Display this name in the navbar as the main nameBOOTSTRAP4_TITLE=None# This is the page title displayed as the browser tab name
- 项目
标签: