Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
62 views
in Technique[技术] by (71.8m points)

javascript - Python Flask App: how to access container environment variables inside java script file

i'm programming a python flask app which has some java script files. There are some environment variables that were defined when the container is deployed to kurbenetes. How to access this variables for a java script file inside an flask application ?

In Python it would be with os.environ['Variable'] = 'some_value'. How about javascript ?

Thank you

question from:https://stackoverflow.com/questions/65884517/python-flask-app-how-to-access-container-environment-variables-inside-java-scri

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am sure there are several viable solutions, but I would use data attributes.

So basically you render the variables via your templates as HTML, and then access them in your JavaScript.

Example from the linked article

<article
  id="electric-cars"
  data-columns="3"
  data-index-number="12314"
  data-parent="cars">
...
</article>

And then you'd access the element and its attributes via JavaScript.

As an alternative, you could generate the JavaScript code from your backend.

As a third way, you could call your backend via http from your JavaScript code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...