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) |
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
Wow. Thanks a bunch @mbr. So much useful and clear info. I definitely learned something (actually, learned way-more than I expected). And interestingly, I was thinking about tackling how to manage configs, so flask-appconfig looks very useful as well.
To be honest, as a side-note, this whole thing started as an experiment using a micro-framework after working for some time with Django/Rails. So my thinking was doing something quick-n-dirty, and keeping almost everything in one file. It is essentially a one-form app to charge credit cards via stripe. I realise that things evolve rather quickly and soon enough you have to start splitting and tidying-up, managing configs etc. So I'm beginning to wonder if micro-frameworks really save so much. But I certainly appreciate the experience, and having kind people to help me like you did is very encouraging, regardless of the framework or technology. I'm very thankful for your help Marc!