【问题标题】:How to change the pinax(0.9a2) template?如何更改 pinax(0.9a2) 模板?
【发布时间】:2012-11-03 16:44:18
【问题描述】:

我已经安装了带有 pinax-bootstrap 主题的 pinax(0.9a2)!

现在我想自定义它并重新设计主题,但我没有在我的模板文件夹中找到任何 *.css 文件。那么如何自定义bootstrap主题的css呢?

【问题讨论】:

    标签: python django windows pinax


    【解决方案1】:

    这就是我启动和运行基本 pinax 项目的方法:-

    mkvirtualenv -p python2.7 --distribute mysite
    cd ~/work
    pinax-admin setup_project -b basic mysite
    cd mysite
    pip install -r requirements/base.txt
    python manage.py collectstatic
    python manage.py syncdb
    python manage.py runserver 8001
    

    这给了我这个:-

    现在我的 pinax 默认使用 bootstrap 主题运行良好,我可以继续使用 CSS 覆盖来自定义我的主题。

    因为我的 pinax settings.py 指向

    # Additional directories which hold static files
    STATICFILES_DIRS = [
        os.path.join(PROJECT_ROOT, "static"),
    ]
    

    我们将把我们所有的css文件放在我们项目根目录“mysite”下的这个静态目录中。

    CSS 覆盖通过在我们的模板中加载引导程序的 css 后加载我们自己的自定义 css 文件来工作。

    我们指定的 CSS 类及其新定义将覆盖引导程序提供的默认值。这就是我们自定义引导主题的方式,同时不理会 bootstrap.css,这也是为什么我们的 static 目录在开始时为空的原因。

    例如,我们的 topbar 类默认定义在 bootstrap.min.css 中。

    .topbar-inner, .topbar .fill {
    background-color: #222;
    ...
    }
    

    我们可以在static目录中指定我们自己的css文件,在我们的templates/site_base.html文件中加载这个css文件并在我们自己的css文件中为顶部栏指定一种新的颜色,如下所示:-

    .topbar-inner, .topbar .fill {
        background-color: red;
        background-image: -webkit-linear-gradient(top, #333, #FF4242);
        background-image: -o-linear-gradient(top, #333, #FF4242);
        background-image: linear-gradient(top, #333, #FF4242);
    }
    

    这将导致我们主页上的黑色顶栏呈现为黑红色。这是使用覆盖来自定义我们的 css 类的基本前提,其默认值已在 bootstrap.min.css 中定义。

    mysite/templates/homepage.html中的示例修改

    {% extends "banner_base.html" %}
    
    {% load i18n %}
    
    {% block extra_head %}
    <link rel="stylesheet" href="{{ STATIC_URL }}css/my_custom_stuff.css">
    {% endblock %}
    
    {% block head_title %}{% trans "Welcome" %}{% endblock %}
    
    {% block body_class %}home{% endblock %}
    
    {% block banner %}
        <h1>{% trans "Welcome to Pinax" %}</h1>
        <p>
            {% blocktrans %}
            <b>Pinax</b> is a <a href="http://djangoproject.com/">Django</a>
            project intended to provide a starting point for websites. By
            integrating numerous reusable Django apps to take care of the
            things that many sites have in common, it lets you focus on what
            makes your site different.
            {% endblocktrans %}
        </p>
    
        <h2>About Zero Project</h2>
        <p>
            {% blocktrans %}
            This project lays the foundation for all other Pinax starter projects. It
            provides the project directory layout and some key infrastructure apps on
            which the other starter projects are based.
            {% endblocktrans %}
        </p>
    
        <p><a href="http://pinaxproject.com/" class="btn primary large">{% trans "Learn more &raquo;" %}</a></p>
    {% endblock %}
    

    添加的具体块是

    {% block extra_head %}
    <link rel="stylesheet" href="{{ STATIC_URL }}css/my_custom_stuff.css">
    {% endblock %}
    

    请注意,我们也可以将其添加到 mysite/templates/site_base.html。这完全取决于您要在我们的my_custom_stuff.css 文件中加载哪个模板。

    my_custom_stuff.css 需要驻留在mysite/static/css 目录中。

    【讨论】:

    • 哇谢谢你的回答!!!最后一个问题,你的意思是:在我们的templates/site_base.html文件中加载这个css文件并在我们自己的css文件中指定???该怎么做?
    • 已更新。和你描述的完全一样。在 site_base.html 或 homepage.html 中加载 css 文件,具体取决于您是否希望 css 覆盖仅应用于主页或扩展到 site_base.html 的所有其他页面。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多