Skip to content

Instantly share code, notes, and snippets.

@Nobutti99
Last active May 11, 2025 14:21
Show Gist options
  • Save Nobutti99/3fa2a996db2ae66c17345ef903dbdaf2 to your computer and use it in GitHub Desktop.
Save Nobutti99/3fa2a996db2ae66c17345ef903dbdaf2 to your computer and use it in GitHub Desktop.
flask get javascript nobutti99
@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.