Skip to content

Instantly share code, notes, and snippets.

@gingerlime
Created February 15, 2014 19:00
Show Gist options
  • Save gingerlime/9023629 to your computer and use it in GitHub Desktop.
Save gingerlime/9023629 to your computer and use it in GitHub Desktop.
trying to use url_prefix with Flask
#!/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)
@gingerlime
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment