Skip to content

Commit 9e7777a

Browse files
authored
Static and media dirs: use absolute path (#819)
* Static dir: absolute path and keep it out from * Media root dir: set absolute path
1 parent e43f62e commit 9e7777a

File tree

8 files changed

+17
-13
lines changed

8 files changed

+17
-13
lines changed

{{ cookiecutter.name }}/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ dmypy.json
111111

112112
venv
113113
.venv
114-
static
115114
.env
116115
db.sqlite
116+
/static
117117
/media

{{ cookiecutter.name }}/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ lint:
2525
uv run dotenv-linter src/app/.env.ci
2626

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

{{ cookiecutter.name }}/src/app/conf/boilerplate.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from pathlib import Path
22

33

4-
BASE_DIR = Path(__file__).resolve().parent.parent
4+
# Repository root directory
5+
BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent
6+
7+
SRC_DIR = BASE_DIR / "src"
58

69
ROOT_URLCONF = "app.urls"
710

{{ cookiecutter.name }}/src/app/conf/environ.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import environ # type: ignore[import-untyped]
22

3-
from app.conf.boilerplate import BASE_DIR
3+
from app.conf.boilerplate import SRC_DIR
44

55

66
env = environ.Env(
77
DEBUG=(bool, False),
88
CI=(bool, False),
99
)
1010

11-
envpath = BASE_DIR / ".env"
11+
envpath = SRC_DIR / "app" / ".env"
1212

1313
if envpath.exists():
1414
env.read_env(envpath)
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from pathlib import Path
2-
3-
from app.conf.boilerplate import BASE_DIR
1+
from app.conf.boilerplate import SRC_DIR
42

53

64
LANGUAGE_CODE = "ru"
75

8-
LOCALE_PATHS = [Path(BASE_DIR).parent / ".locale"]
6+
LOCALE_PATHS = [
7+
SRC_DIR / ".locale",
8+
]
99

1010
USE_i18N = True
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from app.conf.boilerplate import BASE_DIR
12
from app.conf.environ import env
23

34

45
MEDIA_URL = "/media/"
5-
MEDIA_ROOT = env("MEDIA_ROOT", cast=str, default="media")
6+
MEDIA_ROOT = env.path("MEDIA_ROOT", default=BASE_DIR / "media")
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from app.conf.boilerplate import BASE_DIR
12
from app.conf.environ import env
23

34

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

78
STATIC_URL = "/static/"
8-
STATIC_ROOT = env("STATIC_ROOT", cast=str, default="static")
9+
STATIC_ROOT = env.path("STATIC_ROOT", default=BASE_DIR / "static")

{{ cookiecutter.name }}/src/app/management/commands/startapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ class Command(BaseCommand):
77

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

1212
directory.mkdir(exist_ok=True)
1313

1414
options["directory"] = str(directory)
1515

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

1919
options["template"] = str(template)
2020

0 commit comments

Comments
 (0)