My Django dev utilities
These are some useful scripts I usually use while developing Django+Svelte apps. You can find the code here.
The sample app is described in my previous article: My Django-Svelte setup for fullstack development
.gitignore
My .gitignore is the following
echo '.venv
.vscode
.idea
db.sqlite3
__pycache__
**.pyc
staticfiles
.coverage
.pytest_cache' > .gitignore
Dockerfile
mkdir docker
touch docker/Dockerfile
touch docker/entrypoint.sh
docker/Dockerfile
FROM python:slim
ENV PYTHONUNBUFFERED 1
RUN pip install poetry
RUN mkdir /code
WORKDIR /code
COPY pyproject.toml /code
COPY poetry.lock /code
RUN poetry install
ADD frontend /code/frontend/
ADD myapp /code/myapp/
COPY manage.py /code/
ADD docker/entrypoint.sh /code
#ENTRYPOINT ["/bin/bash"]
CMD ["bash", "entrypoint.sh"]
docker/entrypoint.sh
PORT=${1:-8000}
poetry run python manage.py makemigrations
poetry run python manage.py migrate
poetry run python manage.py collectstatic --noinput
poetry run gunicorn --bind 0.0.0.0:$PORT myapp.wsgi
Dev scripts
mkdir -p scripts
echo 'export DJANGO_DEBUG=ON
export LOGGING_LEVEL=DEBUG
poetry run python manage.py "$@"' >> scripts/manage.sh
echo "bash scripts/manage.sh runserver" >> scripts/run-dev-server.sh
echo "bash scripts/manage.sh makemigrations" >> scripts/migrate.sh
echo "bash scripts/manage.sh migrate" >> scripts/migrate.sh
mkdir -p scripts/docker/
echo "docker build -f docker/Dockerfile -t myapp:latest ." > scripts/docker/build.sh
echo "docker run -it --rm -p 8000:8000 myapp:latest" >> scripts/docker/run.sh
Test scripts
poetry add pytest pytest-cov pytest-xdist pytest-django pytest-watch --dev
echo "[pytest]
log_cli = 1
DJANGO_SETTINGS_MODULE = myapp.settings
python_files = tests.py test_*.py *_tests.py" > pytest.init
echo "export DJANGO_DEBUG=ON
export LOGGING_LEVEL=DEBUG
poetry run pytest -n 4 --cov=myapp $1" > scripts/run-tests.sh
echo 'export DJANGO_DEBUG=ON
export LOGGING_LEVEL=DEBUG
poetry run ptw -c -p --runner "pytest --last-failed --new-first $1"' > scripts/run-tests-watch.sh
Top comments (0)