Last active
May 11, 2025 14:21
-
-
Save Nobutti99/3fa2a996db2ae66c17345ef903dbdaf2 to your computer and use it in GitHub Desktop.
flask get javascript nobutti99
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
@app.route("/my-js") | |
def my_js(): | |
js_code = "console.log('Hello from JavaScript!');\n" | |
for k, v in config.SystemConfig.__dict__.items(): | |
if is_num(v): | |
js_code = js_code + "var "+k+" = "+str(v).lower()+";\n" | |
response = make_response(js_code) | |
response.mimetype = "text/javascript" | |
return response | |
def is_num(n): | |
if isinstance(n, int): | |
return True | |
if isinstance(n, float): | |
return True | |
return False | |
<script src="http://127.0.0.1/my-js"></script> |
Comments are disabled for this gist.