1

I need to set some environment variable and it should be fetched inside function and the values will go for save inside the database using Django and Python. My code is below:

def plantsave(request):
    rname = request.POST.get('react')
    status = request.POST.get('status')

Here I am getting the value by post method but instead of it I need to set the value by using environment variable and access those values here to submit.

2 Answers 2

2

You should not use environ for this case, you should use django session for this type of task ref here

Sign up to request clarification or add additional context in comments.

Comments

0

Perhaps you can use django session for that, or just define global variable.

Else :

import os
# set
os.environ["MY_VAR"] = "1"
# get
MY_VAR = os.environ["MY_VAR"]

7 Comments

Ok,In which file I will set this.same views.py file and how i will access it.
In your function directly
Can I set like this rname=os.environ["MY_VAR"] ?
To get yes, answer above was to set
but i have this requiremnt Smart substitution with environment variables can get around some of these santization techniques. and asked to set the vulnerable code.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.