Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add environ variables, env.example #16

Merged
merged 4 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Название, логин и пароль для БД postgres
POSTGRES_DB=postgres_db
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Подпиши комментариями пожалуйста, какие настройки для чего

POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

# Данные для подключения к БД
DB_HOST=db
DB_PORT=5432

# Переменные Django
# ПРЕДУПРЕЖДЕНИЕ: Хранить секретный ключ не должен попадать в общий доступ
SECRET_KEY=secret_key
# ПРЕДУПРЕЖДЕНИЕ: Debug = true использовать только при разработке
DEBUG=True
# Список разрешенных хостов
ALLOWED_HOSTS='localhost 127.0.0.1'

# Переменные бота
# Токен для подключения к Telegram API
TELEGRAM_TOKEN=token
36 changes: 26 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ python = "^3.12"
django = "^5.0.4"
python-telegram-bot = "^21.1.1"
poetry-plugin-export = "^1.7.1"
django-environ= "^0.11.2"
django-asgi-lifespan = "^0.3.1"


[tool.poetry.group.dev.dependencies]
ruff = "^0.4.2"

Expand Down
17 changes: 13 additions & 4 deletions src/core/settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import os
from pathlib import Path

import environ
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У нас poetry в проекте, добавь это пакет в зависимости


env = environ.Env(
DEBUG=(bool, False)
)

BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = "django-insecure-v3b$$**=s5=icl9=sn%p^8o3332r(ams5)vgpv+#ssmep*pq=1"
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))

SECRET_KEY = env('SECRET_KEY')

DEBUG = True
DEBUG = env('DEBUG')

ALLOWED_HOSTS = []
ALLOWED_HOSTS = env('ALLOWED_HOSTS').split()

INSTALLED_APPS = [
"django.contrib.admin",
Expand Down Expand Up @@ -82,4 +91,4 @@

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

TELEGRAM_TOKEN = 'нужно импортировать из environ'
TELEGRAM_TOKEN = env('TELEGRAM_TOKEN')