【问题标题】:Twitter Bootstrap not displaying in TemplateTwitter Bootstrap 未在模板中显示
【发布时间】:2013-09-11 18:44:29
【问题描述】:

我正在关注 https://pypi.python.org/pypi/django-twitter-bootstrap/3.0.0 以将 twitter 引导程序包含到我的网站中。但是,当我测试它时,我没有得到预期的结果。我在引导网站上测试了一些我可以在我的页面上包含的东西,但它们没有被显示。请帮我解决这个问题!谢谢!

这是我的 HTML 文件。

    <!DOCTYPE html>
    <html>
    <body>

    <div class="modal hide fade">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h3>Modal header</h3>
      </div>
      <div class="modal-body">
        <p>One fine body…</p>
      </div>
      <div class="modal-footer">
        <a href="#" class="btn">Close</a>
        <a href="#" class="btn btn-primary">Save changes</a>
      </div>
    </div>

    </body>
    </html>

我已将这些部分添加到我的 settings.py 中:

    INSTALLED_APPS = (
    ...,
    ...,
    'registration',
    'twitter_bootstrap',
    'pipeline',
    'homepage',
    )

    STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

    PIPELINE_COMPILERS = (                          # used for compiling LESS files 
        'pipeline.compilers.less.LessCompiler',
    )

    PIPELINE_CSS = {
        'bootstrap': {
            'source_filenames': (
                'less/bootstrap.less',
            ),
            'output_filename': 'css/b.css',
            'extra_context': {
                'media': 'screen,projection',
            },
        },
    }

    PIPELINE_JS = {
        'bootstrap': {
            'source_filenames': (
              'js/transition.js',
              'js/modal.js',
              'js/dropdown.js',
              'js/scrollspy.js',
              'js/tab.js',
              'js/tooltip.js',
              'js/popover.js',
              'js/alert.js',
              'js/button.js',
              'js/collapse.js',
              'js/carousel.js',
              'js/affix.js',
            ),
            'output_filename': 'js/b.js',
        },
        'application': {
            'source_filenames': (
              'js/holder.js',
              'js/application.js',
            ),
            'output_filename': 'js/a.js',
        }
    }

【问题讨论】:

    标签: python html django twitter-bootstrap


    【解决方案1】:

    您的设置似乎正确,但您还需要加载 html文件中的压缩文件。

    {% load compressed %}
    
    <head>
    {% compressed_js 'bootstrap' %}
    {% compressed_css 'bootstrap' %}
    </head>
    

    阅读django-bootstrap here的文档(自述文件)中的更多用法

    【讨论】:

    • 对 cme​​ts 使用 {# {% compressed_css 'bootstrap'%} #}。此外,less 编译器存在一些问题。该问题已解决here
    • 检查此设置:django-pipeline.readthedocs.org/en/latest/… 您是否更改了默认位置? S
    • 您安装了较少的编译器 (lesscss.org) 吗? (我自己没少用过,不过就是这个样子)
    • 所以我想我成功了!它不漂亮,但它有效!非常感谢您的帮助!我真的很感激!!!
    • 很高兴它有帮助。可能是你用的越多,你就能想出漂亮的做法
    猜你喜欢
    • 1970-01-01
    • 2015-01-31
    • 1970-01-01
    • 1970-01-01
    • 2014-02-10
    • 2012-12-07
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    相关资源
    最近更新 更多