satya
satya

Reputation: 3560

How to set environment variable using Django and Python?

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.

Upvotes: 1

Views: 1400

Answers (2)

glegoux
glegoux

Reputation: 3623

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"]

Upvotes: 0

Swagat
Swagat

Reputation: 632

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

Upvotes: 2

Related Questions