【问题标题】:Twitter bootstrap with Django 1.5Django 1.5 的 Twitter 引导程序
【发布时间】:2013-09-15 21:17:41
【问题描述】:

我正在尝试将 Twitter 引导程序与我的 django 应用程序集成。在 settings.py 中,我有:

STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    "/path/to/my/projects/templates/static/",
)

static文件夹下有css、img、js三个文件夹,所有bootstrap文件都照原样复制进去。

我的模板如下所示:

<html>
    <head>
        {% load staticfiles %}
        <link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap-responsive.css' %}" />
        <script type="text/javascript" src="{% static 'js/bootstrap.js' %}"></script>
        <meta charset="utf-8"> 

        <title>Test App</title>

    </head>
    <body>
        <div class="navbar navbar-fixed-top">  
            <div class="navbar-inner">  
                <div class="container">  
                    <ul class="nav">  
                        <li class="active">  
                            <a class="brand" href="#">TEST APP</a>  
                        </li>  
                        <li><a href="#">About</a></li>  
                        <li><a href="#">Portfolio</a></li>  
                        <li><a href="#">Contact</a></li>  
                    </ul> 
                </div>  
            </div>  
        </div>

然而,当我运行开发服务器时,我得到一个基本的 html 页面,没有任何更改,也没有应用 css。

我在这里做错了什么?

【问题讨论】:

  • 你是在 windows 还是 mac 或 linux 上工作,你的 IDE 是什么?
  • @GamesBrainiac - Fedora 19 和 Eclipse 与 Pydev
  • 然后看看我给你看的代码。这应该可以解决您的问题。
  • 您是否已将 Django 配置为为您提供静态文件?

标签: python html css django twitter-bootstrap


【解决方案1】:

假设您的 static 文件夹就在您的应用程序根目录下,这是一种可用于在所有操作系统上防止静态文件模板呈现的方法。

import os

def replace(path):
    assert isinstance(path, str)
    return path.replace('\\', os.sep)


def here(*args):
    return replace(os.path.abspath(os.path.join(os.path.dirname(__file__), *args)))


BASE_DIR = here('..')


def root(*args):
    return replace(os.path.abspath(os.path.join(BASE_DIR, *args)))

STATICFILES_DIRS = (root('static'),)

【讨论】:

    猜你喜欢
    • 2014-04-21
    • 2014-06-06
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    • 2014-09-09
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多