Created
February 15, 2014 19:00
-
-
Save gingerlime/9023629 to your computer and use it in GitHub Desktop.
trying to use url_prefix with Flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding=utf8 | |
from flask import Flask, Blueprint, redirect, url_for | |
from flask.ext.bootstrap import Bootstrap | |
bp = Blueprint('blueprint', __name__) | |
app = Flask(__name__) | |
Bootstrap(app) | |
app.register_blueprint(bp, prefix='/prefix') | |
# when using `@app.route` this works, but url is `/` | |
# with @bp.route neither `/` nor `/prefix` work | |
@bp.route('/', methods=('GET', 'POST',)) | |
def index(): | |
return 'index' | |
@bp.route('/go_home') | |
def go_home(): | |
return redirect(url_for('index')) | |
if '__main__' == __name__: | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just noticed that in some places in the documentation, e.g. https://pypi.python.org/pypi/Flask-Bootstrap and http://pythonhosted.org/Flask-Bootstrap/bootstrap2.html?highlight=ext#usage - it still shows the deprecated method of importing Bootstrap
from flask.ext.bootstrap import Bootstrap