Skip to content
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
2 changes: 1 addition & 1 deletion {{ cookiecutter.name }}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ dmypy.json

venv
.venv
static
.env
db.sqlite
/static
/media
1 change: 0 additions & 1 deletion {{ cookiecutter.name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ lint:
uv run dotenv-linter src/app/.env.ci

test:
@mkdir -p src/static
uv run pytest --dead-fixtures
uv run pytest --create-db --exitfirst --numprocesses ${SIMULTANEOUS_TEST_JOBS}

Expand Down
5 changes: 4 additions & 1 deletion {{ cookiecutter.name }}/src/app/conf/boilerplate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from pathlib import Path


BASE_DIR = Path(__file__).resolve().parent.parent
# Repository root directory
BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent
Copy link
Contributor

Choose a reason for hiding this comment

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

@nkiryanov а тут не проверял случайно? может Path(__file__).resolve().parent.parent?

file = /project_root/src/app/conf/boilerplate.py
src/app/conf - надо сделать 2 parent, чтобы попасть в root.

Я закину ПР если что. Просто хотел убедиться, что все верно понимаю.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nvo87 BASE_DIR это корень репозитория, не SRC. Для SRC сделали переменную SRC_DIR (она ниже).

Для твоего примера: /project_root/src/app/conf/boilerplate.py:

  1. Path(__file__).resolve() — имя файла
  2. Path(__file__).resolve().parentproject_root/src/app/conf/
  3. Path(__file__).resolve().parent.parentproject_root/src/app/
  4. Path(__file__).resolve().parent.parent.parentproject_root/src/
  5. Path(__file__).resolve().parent.parent.parent.parentproject_root/— как раз что нужно

Copy link
Contributor

Choose a reason for hiding this comment

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

@nkiryanov Блин, да. Сорри, что отвлек.

Тупанул с двумя parent :(( 4 раза parent - это будет project_root.

История в том, что у меня не работает startapp, т.к. она создает папку на два уровня выше, чем src. Я бегло пофиксил, и сам себя убедил, что надо только 2 .parent.

Но потом перестают работать другие manage.py команды, т.к. BASE_DIR был действительно верный.

Сейчас начал разбираться:
в первый раз инициализирует верно
CleanShot 2025-07-22 at 13 47 09@2x

а потом, когда по всем settings прошло, возвращается и отрезает 1 уровень у BASE_DIR.
CleanShot 2025-07-22 at 13 53 09@2x

Но это 99% у меня локальный косяк, а не в бойлерплейте (я решил старый проект обновить на наш бойлерплейт)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

вероятно, аха.
С настройками бывают неочевидные баги: помнится в одном из проектов получилось что импорт настроек запускали дважды. Получалось что в разных местах в коде одна переменная имела разные значения — искал в чём дело несколько часов 😅


SRC_DIR = BASE_DIR / "src"

ROOT_URLCONF = "app.urls"

Expand Down
4 changes: 2 additions & 2 deletions {{ cookiecutter.name }}/src/app/conf/environ.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import environ # type: ignore[import-untyped]

from app.conf.boilerplate import BASE_DIR
from app.conf.boilerplate import SRC_DIR


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

envpath = BASE_DIR / ".env"
envpath = SRC_DIR / "app" / ".env"

if envpath.exists():
env.read_env(envpath)
Expand Down
8 changes: 4 additions & 4 deletions {{ cookiecutter.name }}/src/app/conf/i18n.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from pathlib import Path

from app.conf.boilerplate import BASE_DIR
from app.conf.boilerplate import SRC_DIR


LANGUAGE_CODE = "ru"

LOCALE_PATHS = [Path(BASE_DIR).parent / ".locale"]
LOCALE_PATHS = [
SRC_DIR / ".locale",
]

USE_i18N = True
3 changes: 2 additions & 1 deletion {{ cookiecutter.name }}/src/app/conf/media.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from app.conf.boilerplate import BASE_DIR
from app.conf.environ import env


MEDIA_URL = "/media/"
MEDIA_ROOT = env("MEDIA_ROOT", cast=str, default="media")
MEDIA_ROOT = env.path("MEDIA_ROOT", default=BASE_DIR / "media")
3 changes: 2 additions & 1 deletion {{ cookiecutter.name }}/src/app/conf/static.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from app.conf.boilerplate import BASE_DIR
from app.conf.environ import env


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = "/static/"
STATIC_ROOT = env("STATIC_ROOT", cast=str, default="static")
STATIC_ROOT = env.path("STATIC_ROOT", default=BASE_DIR / "static")
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class Command(BaseCommand):

def handle(self, **options):
if "directory" not in options or options["directory"] is None:
directory = settings.BASE_DIR.parent / options["name"]
directory = settings.SRC_DIR / options["name"]

directory.mkdir(exist_ok=True)

options["directory"] = str(directory)

if "template" not in options or options["template"] is None:
template = settings.BASE_DIR.parent / ".django-app-template"
template = settings.SRC_DIR / ".django-app-template"

options["template"] = str(template)

Expand Down