twitter-bootstrap 如何在 Django 中使用 Bootstrap 主题?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27615506/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 22:02:39  来源:igfitidea点击:

how to use Bootstrap theme in Django?

pythondjangotwitter-bootstrap

提问by Muhammad Taqi

I am new to Python programming and just started Django, I have a small task to use build a bootstrap blog. I have done some work with jinja templates in django. But i want to know how would i use bootstrap 3 in django because django templates work on jinja style like blocks statements and inheritance.

我是 Python 编程的新手,刚开始使用 Django,我有一个小任务要使用构建引导程序博客。我在 django 中做了一些 jinja 模板的工作。但我想知道我将如何在 django 中使用 bootstrap 3,因为 django 模板适用于 jinja 风格,如块语句和继承。

lot of confusion, any one here who have done this sort of work, kindly help. also google it and found a lot of libraries, but the structure is confusing me, keep in mind that i am at beginner level.

很多困惑,这里有做过这种工作的人,请帮忙。也谷歌它并找到了很多图书馆,但结构让我感到困惑,请记住,我处于初学者水平。

回答by Riccardo

You can download the static files and copy them in your project's static library, or you can use them via CDN, that is putting in your template's header links to the Bootstrap CDN:

您可以下载静态文件并将它们复制到您项目的静态库中,或者您可以通过 CDN 使用它们,即将模板的标题链接放入 Bootstrap CDN:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>

回答by doniyor

in django, you have static folderwhich contains css, js and image folders normally.

在 django 中,您有静态文件夹,其中通常包含 css、js 和图像文件夹。

you put bootstrap css files into css folder, js files into js folder and fonts into images.

您将引导程序 css 文件放入 css 文件夹,将 js 文件放入 js 文件夹,将字体放入图像。

and you link to them in template this way:

并以这种方式在模板中链接到它们:

{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/bootstrap.css">

or if you activated staticfiles app, then

或者如果您激活了 staticfiles 应用程序,那么

{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.css' %}">

the same goes for js files. just read django docs, it is the best docs ever!

js 文件也是如此。只需阅读 django 文档,它是有史以来最好的文档!

回答by aus_lacy

I'll echo what the other answers have said, but for a succinct and easy to follow example see:

我将回应其他答案所说的内容,但对于简洁易懂的示例,请参见:

http://www.tangowithdjango.com/book/chapters/bootstrap.html

http://www.tangowithdjango.com/book/chapters/bootstrap.html

for a step by step instruction on how to bootstrap your django app.

有关如何引导 django 应用程序的分步说明。