我是bootstrap的新手(v 3.1.1),我想在我的django项目中使用它。 我在(http://www.tangowithdjango.com/book/chapters/bootstrap.html)中包含所有需要的css和js文件,我可以从我的项目静态URL从Web浏览器访问bootstrap css文件(我的意思是设置文件的正确配置)
但是当我在我的模板中使用bootstrap componenst时它不起作用。例如当为按钮添加bootstrap类时没有任何改变
这是我的base.html文件,其他版本来自base.html模板
{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">`
<link href="{% static 'css/bootstrap.min.css'% }" rel="stylesheet" media="screen">
<link href="{% static 'css/bootstrap-them.min.css' %}" rel="stylesheet">
<title> {% block title %} dance with Django {% endblock %}</title>
</head>
<body>
<div class="btn-group dropup">
<button type="button" class="btn btn-default">Dropup</button>
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu">
<!-- Dropdown menu links -->
</ul>
</div>
{% block body_block %}
{% endblock %}
<script src="{% static 'js/jquery-2.1.0.js"></script>
<script src="{% static 'js/bootstrap.min.js"></script>
</body>
</html>
这里也是我的setting.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rango',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',)
ROOT_URLCONF = 'tango_with_django_project.urls'
WSGI_APPLICATION = 'tango_with_django_project.wsgi.application'
DATABASES = {
'default': {'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'rango.db'),
}
}
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
TEMPLATE_DIRS = ( os.path.join(BASE_DIR, 'templates'),)
STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'),)
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder', )
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',)
TEMPLATE_CONTEXT_PROCESSORS=(
"django.contrib.auth.context_processors.auth",
'django.core.context_processors.request',
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages")
答案 0 :(得分:0)
要启用templatetag {%static%},首先必须加载以下静态文件:
{% load staticfiles %}
在此处详细了解:https://docs.djangoproject.com/en/dev/howto/static-files/