3

I have a django website, and now I want to use bootstrap. I found django-bootstrap3: django-bootstrap3

First I installed the package over pycharm. Like in quickstart, I can load:

{# Load the tag library #}
{% load bootstrap3 %}

{# Load CSS and JavaScript #}
{% bootstrap_css %}
{% bootstrap_javascript %}

{# Display django.contrib.messages as Bootstrap alerts #}
{% bootstrap_messages %}

But for

{% bootstrap_form form %}

I get an error:

Invalid block tag on line 22: 'bootstrap_form', expected 'endblock'. Did you forget to register or load this tag?

how to fix this error?

PS: I have added bootstrap3 to Installed_Apps in my settings.py

6
  • Put all your code until the line 22 Commented Feb 18, 2016 at 11:01
  • Here is the hole file: pastebin.com/RQTfSj8b Commented Feb 18, 2016 at 11:20
  • The code in your site_base.html file Commented Feb 18, 2016 at 11:34
  • My site_base.html: pastebin.com/5da0q6mv Commented Feb 18, 2016 at 11:49
  • Add {% load bootstrap3 %} to child template file after extends Commented Feb 18, 2016 at 12:03

2 Answers 2

6

Add {% load bootstrap3 %} to child template file after the {% extends 'site_base.html' %}.

Sign up to request clarification or add additional context in comments.

2 Comments

Adding that worked for me, but why? I have {% load bootstrap3 %} in my base.html file.
@joshlsullivan Because this is how template tags work. See this question and the answers for more info.
0

Did you put it inside <form> tags ?

This is how your bootstrap form should look (from django-bootstrap3 github page) like:

<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>

3 Comments

yes, i dit. is there a way tho use django-template-inheritance with this package?
If i remove the "block" i get: Invalid block tag on line 22: 'bootstrap_form'. Did you forget to register or load this tag?
You should also start by putting your {% bootstrap_css %} {% bootstrap_javascript %} (not sure for {% bootstrap_messages %} ) in the right place, which means inside the <head> next to <link...> and <script...> and probably the call to jquery before the call to javascript bootstrap. if you inspect the elements of the template page in the browser you'll probably notice some incoherence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.