Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my flask app returning empty pages [closed]

Tags:

python

flask

I am new to Python web frameworks and trying to learn Flask. I went through the tutorial and all was good. I am now trying to make my own little app to learn the framework. I had in my main flask.py file the following code

@app.route('/') 
def index():
    return render_template('main.html')

In main.html I have this html

{% extends "layout.html" %}
{% block content %}
<div> Foo bar test</div>
{% endblock %}

and then in layout.html I have a basic web layout that looks like this

<!DOCTYPE html>       
<title>Flaskpad</title>     
<link href="/static/css/bootstrap.css" rel="stylesheet">    
<link href="/static/css/flaskpad.css" rel="stylesheet">
<style type="text/css">  
.socials {   
padding: 10px;   
}   
</style>  

</head>  
<body>  
    <div class="navbar navbar-fixed-top">  
        <div class="navbar-inner">  
                <div class="container">  
                    <ul class="nav">  
                    <li class="active">  
                            <a class="brand" href="#">Flaskpad/a>  
                    </li>  
                    <li><a href="#">Login</a></li>  
                    <li><a href="#">About</a></li>  
                    <li><a href="#">Contact</a></li>  
                </ul> 
            </div>
        </div>
    </div>
    <div class="container">
        <div class="row fcontent">
            <div class="span3">
                Empty Space
            </div>
            <div class="span6 maincontent">
                {% block content %}{% endblock %}
            </div>
            <div class="span3">
                Empty Space
            </div>
        </div>
        <div class="row ffooter">
            <div class="span12">
                Made by Bar Foo
            </div>
        </div>
    </div> 
</body>  

I know the css links are done incorrectly but I just have them there as placeholders. Now when I run python flask.py and go to localhost:5000 the page turns up blank and I cannot figure out why. If I put in normal text in the main.html before the extends that will show up so I know it is loading main.html but it seems to not be extending the layout. The page literally is blank as when you view source there is nothing. I cannot figure this out.

like image 388
Reily Bourne Avatar asked Aug 31 '12 01:08

Reily Bourne


1 Answers

Works for me. Do you have your HTML files in a folder named "templates" relative to your python module?

Here's my full test code.

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('main.html')

if __name__ == '__main__':
    app.run()

Edit: You said: "I had in my main flask.py file the following code" - You should probably not name it flask.py, this may be screwing things up.

like image 56
FogleBird Avatar answered Sep 30 '22 13:09

FogleBird