Terryb
Terryb

Reputation: 51

Flask-bootstrap simple app not rendering bootstrap correctly

I'm having some problems to get a simple flask app to use the flask-bootstrap package.

Following the documentation I installed flask-bootstrap, created the 2 files below and this worked fine. The problem I'm facing is that when I access index.html in the browser I see only the text bootstrap/base.html returned and see no reference to the bootstrap css files when I view the source.

Appreciate any guidance on what I am missing here. Thanks.

__init__.py

from flask import Flask, render_template

from flask.ext.bootstrap import Bootstrap 

app = Flask(__name__)
bootstrap = Bootstrap(app)

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

if __name__ == "__main__":
    app.run(debug=True)

index.html

{% extends "bootstrap/base.html" %}
{% block title %}This is an example page{% endblock %}

{% block navbar %}
<div class="navbar navbar-fixed-top">
  <!-- ... -->
</div>
{% endblock %}

{% block content %}
  <h1>Hello, Bootstrap</h1>
{% endblock %}

Upvotes: 3

Views: 2561

Answers (1)

Terryb
Terryb

Reputation: 51

Thank you for the hints regarding the setup and proper use of virtualenv.

After some further digging I discovered that I should have the following 2 lines added to the top of flaskapp.wsgi since I installed bootstrap on the virtual environment created for my app, namely venv

activate_this = '/var/www/FlaskApp/FlaskApp/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

Upvotes: 1

Related Questions