Volatil3
Volatil3

Reputation: 14998

How to extend Django CMS template?

I want to use a base template and then extend partial views. extends not working as it is not showing base markup at all.

base.html

<div class="container">
    {% block content %}
    {% endblock %}
</div>

_hello.html

    {% extends 'base.html' %}
   {% block content %}
    <div class="container">
        <div class="row">
            <div class="col-md-12 text-center"><h2>Survey About Computer Programming</h2></div>
        </div>
        <div class="row">
            <div class="col-md-12">
                <h3>Programming</h3>
                <table class="table table-bordered table-striped table-responsive">
                    <thead>
                        <tr align="center">
                            <th>Main</th>
                            <th class="text-center">Option1</th>
                            <th class="text-center">Option2</th>
                            <th class="text-center">Option3</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Do you love Programming?</td>
                            <td class="text-center"><input type="radio" class=""></td>
                            <td class="text-center"><input type="radio" class=""></td>
                            <td class="text-center"><input type="radio" class=""></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>

    </div>
    <script src="/static/survey/js/plugin.js"></script>
 {% endblock %}

Upvotes: 0

Views: 455

Answers (2)

Mayank Pratap Singh
Mayank Pratap Singh

Reputation: 183

You Missed important thing whenver we are creating template like this we have to make sure every block like CSS, Content, JS must be defined proporly in base html file. And when you extends this base template then you have to framed your content as per requirement. Like if you need to put some content in the html page which extends the base html simply call as following {% block _block_name_should_be_here %} {% endblock %}

Block name might be like css_part , content_part , js_part which needs to be used the html page.

Upvotes: 0

Alex
Alex

Reputation: 6047

you have to put your code inside the block content . The extended template overwrites the blocks in the base template.

<div class="container">
    {% block content %}
    {% endblock %}
</div>
    {% block js_bottom %}
    {% endblock %}

_hello.html

{% extends 'base.html' %}
{% block content %}
<div class="row">
    <div class="col-md-12 text-center"><h2>Survey About Computer Programming</h2></div>
</div>
<div class="row">
    <div class="col-md-12">
        <h3>Programming</h3>
        <table class="table table-bordered table-striped table-responsive">
            <thead>
                <tr align="center">
                    <th>Main</th>
                    <th class="text-center">Option1</th>
                    <th class="text-center">Option2</th>
                    <th class="text-center">Option3</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Do you love Programming?</td>
                    <td class="text-center"><input type="radio" class=""></td>
                    <td class="text-center"><input type="radio" class=""></td>
                    <td class="text-center"><input type="radio" class=""></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
    {% endblock %}

{% block js_bottom %}
<script src="/static/survey/js/plugin.js"></script>
{% endblock %}

Upvotes: 1

Related Questions