简体   繁体   English

Django与Twitter Bootstrap3和主题

[英]Django with Twitter Bootstrap3 and Themes

I've been researching this a long time and experimenting and I can't seem to figure out what the best way to go about accomplishing this. 我已经研究了很长时间并进行了实验,我似乎无法弄清楚实现这一目标的最佳方法。 I know I'm doing it wrong so some clarification as well as some quick examples would help a lot. 我知道我做错了所以一些澄清以及一些简单的例子会有很大帮助。

I was wondering about using a bootstrap3 theme from https://wrapbootstrap.com/ with Django. 我想知道如何使用https://wrapbootstrap.com/和Django的bootstrap3主题。 I researched into the django-bootstrap3 and django-bootstrap-themes packages. 我研究了django-bootstrap3和django-bootstrap-themes包。 On the github page of django-bootstrap-themes it says it's compatible with bootswatch. 在django-bootstrap-themes的github页面上,它表示它与bootswatch兼容。 I don't like their themes so I was wondering if it was compatible with wrapbootstrap.com themes. 我不喜欢他们的主题所以我想知道它是否与wrapbootstrap.com主题兼容。 The themes I would select from wrapbootstrap.com are Responsive HTML themes. 我将从wrapbootstrap.com中选择的主题是响应式HTML主题。 I wanted to know if out of personal experience anyone knows which of these packages are best for using themes from wrapbootstrap.com with django. 我想知道,如果出于个人经验,任何人都知道哪些包最适合使用来自wrapbootstrap.com和django的主题。

I understand it is possible to just take from the theme the stylesheets, scripts, place them into their respective folders in static, and turn the HTML base into a base template as well as other pages. 我理解可以从主题中获取样式表,脚本,将它们放入静态的各自文件夹中,并将HTML基础转换为基本模板以及其他页面。 Then install bootstrap from a CDN. 然后从CDN安装bootstrap。 I know this is also possible with django-bootstrap3. 我知道这也可以用django-bootstrap3。 But I can't find the answer anywhere as to what is currently the best way to go about integrating one of those themes and twitter bootstrap3 into a Django website, and some quick examples of doing this. 但我无法找到答案,目前最好的方法是将其中一个主题和twitter bootstrap3集成到Django网站中,以及一些快速的例子。

Thanks, and any advice for doing so would help a ton. 谢谢,任何这样做的建议都会有所帮助。

The package django-bootstrap3 is a nice utility app which allows you to produce less HTML markup in your templates that would be otherwise required for bootstrap to work. django-bootstrap3是一个很好的实用程序应用程序,它允许您在模板中生成较少的HTML标记,否则引导程序将起作用。 It uses some additional template tags for this purpose. 它为此目的使用了一些额外的模板标签。

I find this package a nice one and sometimes I use it, but it is usually after you have got involved well into bootstrap that you appreciate it. 我发现这个包很好用,有时我会用它,但通常在你很好地参与到引导程序之后你就会欣赏它。

The package django-bootstrap-themes seems to be an app which it too offers some template tags like the former package, but apparently less. django-bootstrap-themes似乎是一个应用程序,它也提供了一些模板标签,如前一个包,但显然更少。 But it also allows you to easily integrate themes from Bootswatch into your Django templates, which is nice if you find those templates appealing. 但它也允许您轻松地将Bootswatch中的主题集成到您的Django模板中, 如果您发现这些模板很有吸引力,这很不错。 Other than that I personally find no other reason to use it. 除此之外,我个人认为没有其他理由可以使用它。 But again, both packages could be used together if it fits you. 但同样,如果它适合你,两个包可以一起使用。

Some examples: 一些例子:

In order to get bootstrap going in your templates without any other package, you would have to include the following in your base html file: 为了在没有任何其他包的模板中获取引导程序,您必须在基本html文件中包含以下内容:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
{# HTML5 shiv and Respond.js for IE8 support of HTML5 elements and media queries #}
{# WARNING: Respond.js doesn't work if you view the page via file:// #}
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->

And at the bottom: 在底部:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

With django-bootstrap3 this becomes : 使用django-bootstrap3,将成为

{% load bootstrap3 %}
{% bootstrap_css %}
{% bootstrap_javascript %}

But some other markup gets very much simplified. 但是其他一些标记变得非常简单。 For instance a bootstrap form (see the official docs example ) would become easy as: 例如,引导表单(请参阅官方文档示例 )将变得简单:

<form action="/url/to/submit/" method="post" class="form">
  {% csrf_token %}
  {% bootstrap_form form %}
  {% buttons %}
    <button type="submit" class="btn btn-primary">
      {% bootstrap_icon "star" %} Submit
    </button>
  {% endbuttons %}
</form>

To load bootstrap with django-bootstrap-themes : 使用django-bootstrap-themes加载引导程序

{% load bootstrap_themes %}
{% bootstrap_script use_min=True %}

And apparently this is how you would use one of the themes from bootswatch: 显然,这就是你如何使用bootswatch中的一个主题:

{% bootstrap_styles theme='cosmo' type='min.css' %}

To sum up, if you wish to use any other ready-made bootstrap theme in your templates, you would still need to go with the standard approach that you describe in your question, possibly using some of the above tools on top. 总而言之,如果您希望在模板中使用任何其他现成的引导主题,您仍然需要使用您在问题中描述的标准方法,可能使用上面的一些上述工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM