-
Notifications
You must be signed in to change notification settings - Fork 39
Static and media dirs: use absolute path #819
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
Conversation
cd7dc55 to
2696533
Compare
kazqvaizer
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А какую проблему ты тут решаешь?
2696533 to
e3b4ca7
Compare
e3b4ca7 to
cf91ae1
Compare
У статики и медиа становится абсолютный путь, то есть не зависит откуда запускаем приложение или тесты. Релатив путь даже нам создавал проблемы: например в тестах ворнинг что папки со статикой нет. Чтоб починить мы даже стали создавать папку для статики в Makefile, хотя статика собирается в bootstrap и чинили следствие, а не оригинальную проблему. |
|
|
||
| BASE_DIR = Path(__file__).resolve().parent.parent | ||
| # Repository root directory | ||
| BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent |
There was a problem hiding this comment.
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.
Я закину ПР если что. Просто хотел убедиться, что все верно понимаю.
There was a problem hiding this comment.
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:
Path(__file__).resolve()— имя файлаPath(__file__).resolve().parent—project_root/src/app/conf/Path(__file__).resolve().parent.parent—project_root/src/app/Path(__file__).resolve().parent.parent.parent—project_root/src/Path(__file__).resolve().parent.parent.parent.parent—project_root/— как раз что нужно
There was a problem hiding this comment.
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 был действительно верный.
Сейчас начал разбираться:
в первый раз инициализирует верно

а потом, когда по всем settings прошло, возвращается и отрезает 1 уровень у BASE_DIR.

Но это 99% у меня локальный косяк, а не в бойлерплейте (я решил старый проект обновить на наш бойлерплейт)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вероятно, аха.
С настройками бывают неочевидные баги: помнится в одном из проектов получилось что импорт настроек запускали дважды. Получалось что в разных местах в коде одна переменная имела разные значения — искал в чём дело несколько часов 😅
Здесь решаем:
Общая идея:
BASE_DIRбудем восприниматьsrc