我正在阅读使用文档作为模板的bootstrap3-django。我不明白{% bootstrap_css %}的目的。我看了一下这个标签的source code,但是我不明白它的目的是什么?
在我的base.html模板中,我有:
{% load static from staticfiles %}
{% load bootstrap3 %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %}{% endblock %}</title>
{% bootstrap_css %}
<link href="{% static "css/custom.css" %}" rel="stylesheet">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>这里有{% bootstrap_css %}和css links从homepage到bootstrap css
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">没有这一点,页面就不会使用Bootstrap3。那么,{% bootstrap_css %}的目的是什么,为什么要使用它呢?
谢谢
发布于 2014-04-03 00:19:19
有时最好是挖掘源头。bootstrap_css templatetag 代码可以在这里找到。看起来像是将bootstrap.min.css和潜在的主题url嵌入到页面中。
@register.simple_tag
def bootstrap_css():
"""
Return HTML for Bootstrap CSS
Adjust url in settings. If no url is returned, we don't want this statement to return any HTML.
This is intended behavior.
Default value: ``FIXTHIS``
This value is configurable, see Settings section
**Tag name**::
bootstrap_css
**usage**::
{% bootstrap_css %}
**example**::
{% bootstrap_css %}
"""
urls = [url for url in [bootstrap_css_url(), bootstrap_theme_url()] if url]
return ''.join([render_link_tag(url, media='screen') for url in urls])https://stackoverflow.com/questions/22825357
复制相似问题