【问题标题】:django-bootstrap3 - what is the purpose of bootstrap_css?django-bootstrap3 - bootstrap_css 的目的是什么?
【发布时间】:2014-05-14 13:22:09
【问题描述】:

我正在阅读 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 linksbootstrap csshomepage

<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 %}的目的是什么,为什么要使用它呢?

谢谢

【问题讨论】:

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


    【解决方案1】:

    有时最好挖掘源头。 bootstrap_css 模板标签 code can be found here. 看起来它嵌入了 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])
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-23
    • 2020-06-15
    • 2011-11-14
    • 1970-01-01
    • 2013-11-19
    • 1970-01-01
    • 2011-03-05
    • 2015-03-21
    相关资源
    最近更新 更多