How to use multiple templates that inherits from one base template? python, Flask
Question: I have my directory structure as such (from
<https://github.com/alvations/APE>):

    
    
    APE
        \app
            \templates
                base.html
                index.html
                instance.html
            __init__.py
            hamlet.py
        config.py
        run.py
    

My `hamlet.py` application, initializes 2 pages with these functions:

    
    
    from flask import render_template
    from app import app
    
    @app.route('/')
    @app.route('/index')
    @app.route('/instance')
    
    def index():
        return render_template('index.html')
    
    def instance():
        return render_template('instance.html')
    

And the `instance.html` and `index.html` are both inheriting from `base.html`
with different block content, the base.html looks as such:

    
    
    <!DOCTYPE html>
    <html lang="en">
    
        <head>
            <title>Post Editor Z</title>
        </head>
    
        <body>
    
            <div class="container">
                {% block content %}{% endblock %}
            </div><!-- /.container -->
    
        </body>
    </html>
    

My index.html looks like this:

    
    
    {% extends "base.html" %}
    {% block content %}    
     <div class="row">
        <div class="col-lg-12">
          Hello World
        </div>
     </div>
    {% endblock %}
    

And my instance.html looks like this:

    
    
    {% extends "base.html" %}
    {% block content %}    
     <div class="row">
        <div class="col-lg-12">
          Some instance.
        </div>
     </div>
    {% endblock %}
    

After deploying and going to `http://127.0.0.1:5000/index` and
`http://127.0.0.1:5000/instance`. They were both giving the content of
`index.html`

**Is that because base.html can only be inherited by one other html? In my
case, I have both`instance` and `index` html inheriting from base.html.**

I have tried making a copy of `base.html` and call it `abase.html` and made
`instance.html` inherits from `abase.html` but `instance.html` still outputs
`Hello World` instead of `Some instance.`, i.e. i did this change to
`instance.html`:

    
    
    {% extends "abase.html" %}
    {% block content %}    
     <div class="row">
        <div class="col-lg-12">
          Hello World
        </div>
     </div>
    {% endblock %}
    

**How do I resolve the problem such that instance.html and index.html will
display the two different pages as defined in the templates?**

Is it because I am initializing my pages wrongly in `hamlet.py`?


Answer: I found the fix for the problem but I don't know why it works.

Shifting the `@app.route('/instance')` to before the `instance()` worked:

    
    
    from flask import render_template
    from app import app
    
    @app.route('/')
    
    @app.route('/index')
    def index():
        return render_template('index.html')
    
    @app.route('/instance')
    def instance():
        return render_template('instance.html')
    

