若是您正在寻找与Django 1.8兼容的版本,只需安装0.3.7.1。html
pypi(推荐)django
$ pip install bootstrap-admin
django.contrib.admin以前在INSTALLED_APPS中添加bootstrap_adminbootstrap
INSTALLED_APPS = ( # ... 'bootstrap_admin', # always before django.contrib.admin 'django.contrib.admin', # ... )
侧边栏菜单api
它是默认启用的。可是若是删除django.template.context_processors。来自context_processors的请求。app
setting中设置禁用侧边栏菜单url
BOOTSTRAP_ADMIN_SIDEBAR_MENU = False
若是但愿使用本身的品牌logo,能够经过覆盖login.html和base_site来实现html,就像Django管理同样。确保正确配置了settings.py中的模板设置:spa
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, 'my_django_project/templates')], 'APP_DIRS': True, # other stuff }, ]
你必须设置模板的位置,一个绝对路径。code
假设BASE_DIR是:htm
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
建立全局模板文件夹的这种模式对于您用于base.html和其余全局模板可能颇有用。blog
更多信息:
https://docs.djangoproject.com/en/2.1/ref/templates/api/ # configuring-an-engine
示例结构
├── my_django_project │ ├── core │ │ ├── admin.py │ │ ├── apps.py │ │ ├── models.py │ │ ├── tests.py │ │ └── views.py │ ├── settings.py │ ├── templates │ │ └── admin │ │ ├── base_site.html │ │ └── login.html │ ├── urls.py │ └── wsgi.py ├── manage.py
您能够看到,我建立了一个全局模板/文件夹,admin/中还有一个目录包含login.html和base_site.html。
它们各自的内容以下:
base_site.html
{% extends 'admin/base_site.html' %} {% load static %} {% block branding %} <a href="{% url 'admin:index' %}" class="django-admin-logo"> <!-- Django Administration --> <img height="60" src="{% static "bootstrap_admin/img/logo-140x60.png" %}" alt="{{ site_header|default:_('Django administration') }}"> </a> {% endblock branding %}
login.html
{% extends 'admin/login.html' %} {% load i18n static %} {% block branding %} <a href="{% url 'admin:index' %}" class="django-admin-logo"> <!-- Django Administration --> <img height="60" src="{% static "bootstrap_admin/img/logo-140x60.png" %}" alt="{{ site_header|default:_('Django administration') }}"> </a> {% endblock branding %}
更多信息:
https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#admin-overriding-templates