I want to know how can i define some constants in django and use them in view.py function. I have some variables which are never going to be changed and are used in a function many a time. So i decided to define them as constants.
If any one can help me with the declaration of constants and how to import and use them in a function in views.py
EDIT:
constant.py
total_range='A1:C15'
view.py
from constant import *
def myFunction():
***Code to access google spreadsheet**
cell_value_list=worksheet.range(total_range)
here it gives me an error saying total_range is not defined.
Define a variable like this i settings.py
:
MY_VAR = "MY_VALUE"
Import settings in views.py
:
from django.conf import settings
You can use your variable in views.py
like this:
settings.MY_VAR
You can make a seprate file beside views.py and define all constants on it.
for example create constants.py
like this:
const1 = 'value1'
const2 = 'value2'
.
.
.
Now you can use constants in views.py like this:
from constants import *
print const1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With