Last active
February 20, 2023 09:59
-
-
Save spantaleev/4433109 to your computer and use it in GitHub Desktop.
Flask-Sijax usage example with blueprints
This file contains hidden or 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
*.pyc | |
env | |
static/js |
This file contains hidden or 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
This file contains hidden or 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
import os | |
from flask import Flask, redirect, url_for | |
import flask_sijax | |
from myapp.myblueprint import blueprint | |
app = Flask(__name__) | |
app.config["SIJAX_STATIC_PATH"] = os.path.join('.', os.path.dirname(__file__), 'static/js/sijax/') | |
app.config["SIJAX_JSON_URI"] = '/static/js/sijax/json2.js' | |
flask_sijax.Sijax(app) | |
app.register_blueprint(blueprint) | |
@app.route('/') | |
def index(): | |
return redirect(url_for('myblueprint.index')) | |
if __name__ == '__main__': | |
app.run(debug=True, port=5555) |
This file contains hidden or 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
from flask import Blueprint, url_for, g, render_template | |
import flask_sijax | |
blueprint = Blueprint('myblueprint', __name__, url_prefix='/myblueprint', template_folder='templates') | |
@flask_sijax.route(blueprint, '/') | |
def index(): | |
def say_hi(obj_response): | |
obj_response.alert('Hi there!') | |
if g.sijax.is_sijax_request: | |
g.sijax.register_callback('sayHi', say_hi) | |
return g.sijax.process_request() | |
return render_template('page.html') |
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<script type="text/javascript" | |
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> | |
<script type="text/javascript" src="/static/js/sijax/sijax.js"></script> | |
<script type="text/javascript"> | |
{{ g.sijax.get_js()|safe }} | |
</script> | |
</head> | |
<body> | |
<a href="javascript://" onclick="Sijax.request('sayHi');">Say Hi!</a> | |
</body> | |
</html> |
This file contains hidden or 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
Flask | |
flask-sijax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment