-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example Flask integration #17
Conversation
I have appended an example of a Flask integration.
👍 |
1 similar comment
👍 |
Actually this example it not working at all ive tried it with from flask import Flask, render_template
import bowerstatic
import os.path
app = Flask(__name__)
bower = bowerstatic.Bower()
components = bower.components(
"components",
os.path.join(os.path.dirname(__file__), "static", "bower"),
)
@app.route('/')
def home():
from flask import request
include = components.includer(request.environ)
include('jquery/dist/jquery.js')
return "Hello World!" # render_template("foo.html")
if __name__ == "__main__":
app.wsgi_app = bower.wrap(app.wsgi_app)
app.run(debug=True) Resulting html: % curl http://127.0.0.1:5000/
Hello World!% |
Hm, I wonder what the cause of this is, do I understand you that the Could you check whether Or perhaps it's the reason for the before_request story -- maybe it's otherwise somehow overwritten? Does it work with before_request? |
Yes the
Also the with from flask import Flask
from flask import request
import bowerstatic
import os.path
app = Flask(__name__)
bower = bowerstatic.Bower()
components = bower.components(
"components",
os.path.join(os.path.dirname(__file__), "static", "bower"),
)
@app.before_request
def include_js_css():
include = components.includer(request.environ)
include('jquery/dist/jquery.min.js')
@app.route('/')
def home():
include = components.includer(request.environ)
include('jquery/dist/jquery.js')
return "Hello World!"
if __name__ == "__main__":
app.wsgi_app = bower.wrap(app.wsgi_app)
app.run(debug=True) The
|
Ok figured it out if i add How is from flask import Flask
from flask import request
import bowerstatic
import os.path
app = Flask(__name__)
bower = bowerstatic.Bower()
components = bower.components(
"components",
os.path.join(os.path.dirname(__file__), "static", "bower"),
)
@app.route('/')
def home():
include = components.includer(request.environ)
include('jquery/dist/jquery.js')
return "<head></head>Hello World!"
if __name__ == "__main__":
app.wsgi_app = bower.wrap(app.wsgi_app)
app.run(debug=True) Output:
|
Oh, glad you figured it out! Yes, it needs a Bower publishes the /bowerstatic URLs using its own file-based publisher through a WSGI middleware. The bower.wrap() call takes care of this. Doesn't it complete loading the jquery? Once I get positive feedback that this works I'll finally merge the pull request. I now have enough examples of Flask integration to know how to create a small example in the docs! |
It works , after a bit of debugging, the path [1] from flask import Flask
from flask import request
import bowerstatic
import os.path
app = Flask(__name__)
bower = bowerstatic.Bower()
components = bower.components(
"components",
os.path.join(
os.path.abspath(os.path.dirname(__file__)),
"static", "bower"),
)
@app.route('/')
def home():
include = components.includer(request.environ)
include('jquery/dist/jquery.js')
return "<head></head>Hello World!"
if __name__ == "__main__":
app.wsgi_app = bower.wrap(app.wsgi_app)
app.run(debug=True) Output:
|
I have appended an example of a Flask integration as per your request.