django-bootstrap3 - bootstrap_css的目的是什么?

时间:2014-04-02 23:59:27

标签: css django twitter-bootstrap django-templates twitter-bootstrap-3

我正在阅读docs,以便使用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 bootstrap css homepage
<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 %}的目的是什么以及为什么要使用它?

由于

1 个答案:

答案 0 :(得分:3)

有时候最好深入挖掘资料来源。 bootstrap_css templatetag code can be found here.看起来像是将bootstrap.min.css和主题网址嵌入到页面中。

@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])