Evgenii Legotckoi
Sept. 18, 2016, 6:48 p.m.

Django - Tutorial 004. Implementing Bootstrap 3 to site on the Django

Web site design and layout are pretty important issues, and sometimes it would be desirable to develop a website with good and interesting design ... but ... not all of us are designers, and even less good designers. So it was easier for me to take Bootstrap 3, to find a good skin for him, or rather in the same style customized CSS, and not bothered to start development of the site with the already proven by many web-masters of the instrument.

Let's see how to do it with Bootstrap 3 in Django .


django-bootstrap3

So, there is a ready Django application django-bootstrap3 , you want to install, connect, and use add the necessary components in the head tag on your pages.

Installing

Installing the application is executed by using pip utility, be sure to only activate the virtual environment.

  1. pip install django-bootstrap3

Implementing

Before using Bootstrap, it must be connected in the configuration file.

  1. INSTALLED_APPS = [
  2. ...
  3. 'bootstrap3',
  4. ...
  5. ]
  6.  

Using

Bootstrap module for Django can be used as a ready-made forms, without spending time on page-proofs and easy to use styles and jQuery library, which is used for this current version of Bootstrap.

For example, for minimum connection it is enough to connect styles files and script of Bootstrap in the head tag.

  1. {% load bootstrap3 %}
  2. <script src="{% bootstrap_jquery_url %}"></script>
  3. {% bootstrap_javascript %}
  4. {% bootstrap_css %}

If you want to use fast customization form in bootstrap style, it will also need to specify the connection module in the template and use the template form for the module.

  1. {% load bootstrap3 %}
  2.  
  3. {# Display a form #}
  4.  
  5. <form action="/url/to/submit/" method="post" class="form">
  6. {% csrf_token %}
  7. {% bootstrap_form form %}
  8. {% buttons %}
  9. <button type="submit" class="btn btn-primary">
  10. {% bootstrap_icon "star" %} Submit
  11. </button>
  12. {% endbuttons %}
  13. </form>

For Django I recommend VDS-server of Timeweb hoster .

BL4CK R4BBIT
  • Aug. 4, 2019, 2:54 p.m.
  • (edited)

Как вариант 1

  1. <head> #base.html
  2. {% load bootstrap4 %}
  3. {% bootstrap_css %}
  4. {% bootstrap_javascript jquery='full' %}
  5. </head>
  6.  
  7. {% extends "base.html" %}
  8. {% load bootstrap4 %}
  9.  
  10.  
  11. <form method="post">
  12. {% csrf_token %}
  13. {% bootstrap_form form layout='vertical' %}
  14. {% buttons submit='Сохранить' %}{% endbuttons %}
  15. </form>

вариант 2

  1. <head> #base.html
  2. {% load bootstrap4 %}
  3. {% bootstrap_css %}
  4. {% bootstrap_javascript jquery='slim' %}
  5. </head>
  6.  
  7. {% extends "base.html" %}
  8. {% load bootstrap4 %}
  9. {% bootstrap_button content %}
  10.  
  11. <form method="post">
  12. {% csrf_token %}
  13. {% bootstrap_form form layout='gorizontal' %}
  14. {% bootstrap_button "Сохранить" button_type="submit" button_class="btn-primary" %}
  15. </form>
BL4CK R4BBIT
  • Aug. 4, 2019, 3:03 p.m.

И кстати заметил что прописывать скрипты бутстрапа {% bootstrap_javascript jquery='slim' %} надо все таки в footer. Так как могут не отработать объекты в других скриптах именно из-за очередности загрузки

Comments

Only authorized users can post comments.
Please, Log in or Sign up
  • Last comments
  • Evgenii Legotckoi
    March 9, 2025, 9:02 p.m.
    К сожалению, я этого подсказать не могу, поскольку у меня нет необходимости в обходе блокировок и т.д. Поэтому я и не задавался решением этой проблемы. Ну выглядит так, что вам действитель…
  • VP
    March 9, 2025, 4:14 p.m.
    Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
  • ИМ
    Nov. 22, 2024, 9:51 p.m.
    Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
  • Evgenii Legotckoi
    Oct. 31, 2024, 11:37 p.m.
    Добрый день. Да, можно. Либо через такие же плагины, либо с постобработкой через python библиотеку Beautiful Soup
  • A
    Oct. 19, 2024, 5:19 p.m.
    Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html