Django / Grade 1 / Переменные окружения
pip install python-dotenv
from dotenv import load_dotenv
load_dotenv()
bot = telebot.TeleBot(os.environ.get('TELEGRAM_TOKEN'))
https://django-environ.readthedocs.io/en/latest/install.html
pip install django-environ
import environ
env = environ.Env()
BASE_DIR = ...
environ.Env.read_env(BASE_DIR / '.env')
env = environ.Env(
DEBUG=(bool, False),
)
from django.conf import settings
x = settings.TELEGRAM_TOKEN
пример синтаксиса:
ALLOWED_HOSTS=127.0.0.1,localhost,188.68.220.202
ALLOWED_HOSTS = env.list('ALLOWED_HOSTS')