display environment in wsgi 4
display environment in wsgi 4

How To Display Environment Variables List

Posted on

The list of environment variables in WSGI application can be displayed using python code. But before that, you may want to see how to create WSGI aplication. To display the list of environment, firstly I create file named env.py and copy-paste the following code and don’t forget to save.

Then I place the file in my work directory called D:\personal\flaskApp\pythoneveryday

Next step, activate my existed python environment which I already installed before. See how to create virtual environment for Python using Anaconda.

Next, I run the file env.py like following

Next, I open my browser and write http://localhost:5000 on the address bar to see what will happen

Explanation for codes in env.py
The environ.items() command will return a dictionary object containing all environment variables. The variable name will be used as the key and the contents of the variable will be used as the value of the dictionary object. Therefore, we can display the list of elements contained in the dictionary object using the following code

by the code in sorted(environ.items()) above, the elements in the dictionary will be firsly sorted using the before being displayed.

Congratulation! now I can display the list of environment variables in WSGI application.

Leave a Reply

Your email address will not be published. Required fields are marked *