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

feat(async): add uvicorn, asgi, upgrade django=4.1 #473

Merged
merged 13 commits into from
Nov 27, 2023
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

## Features

- Django 3.2.x
- Django 4.1.x
- Python 3.9.x
- [Poetry][poetry] Support
- Support for [black](https://pypi.org/project/black/)!
Expand Down
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
, "add_django_auth_wall": "y"
, "add_celery": "n"
, "add_graphql": "n"
, "add_asgi": "n"
, "add_pre_commit": "y"
, "add_docker": "y"
, "pagination": ["LimitOffsetPagination", "CursorPagination"]
Expand Down
6 changes: 6 additions & 0 deletions hooks/post_gen_project.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ if echo "{{ cookiecutter.add_graphql }}" | grep -iq "^n"; then
rm -rf tests/graphql
fi

if echo "{{ cookiecutter.add_asgi }}" | grep -iq "^n"; then
rm -rf asgi.py
else
rm -rf wsgi.py
fi

if echo "$yn" | grep -iq "^y"; then
echo "==> Checking system dependencies. You may need to enter your sudo password."

Expand Down
16 changes: 16 additions & 0 deletions {{cookiecutter.github_repository}}/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Standard Library
import os

# Third Party Stuff
from django.core.asgi import get_asgi_application
from dotenv import load_dotenv

# Read .env file and set key/value inside it as environment variables
# see: http://github.com/theskumar/python-dotenv
load_dotenv(os.path.join(os.path.dirname(__file__), ".env"))

# We defer to a DJANGO_SETTINGS_MODULE already in the environment.
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings.development'
# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.production")
sun337 marked this conversation as resolved.
Show resolved Hide resolved

application = get_asgi_application()
5 changes: 4 additions & 1 deletion {{cookiecutter.github_repository}}/compose/dev/django/start
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ set -o nounset


python /app/manage.py collectstatic --noinput
# /usr/local/bin/gunicorn asgi --bind 0.0.0.0:5000 --chdir=/app -k uvicorn.workers.UvicornWorker
{%- if cookiecutter.add_asgi.lower() == "y" %}
/usr/local/bin/gunicorn asgi --bind 0.0.0.0:5000 --chdir=/app -k uvicorn.workers.UvicornWorker
{%- else %}
/usr/local/bin/gunicorn wsgi --bind 0.0.0.0:5000 --chdir=/app --access-logfile - --error-logfile -
{%- endif %}
sun337 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 5 additions & 1 deletion {{cookiecutter.github_repository}}/compose/local/start
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@ set -o nounset


python manage.py migrate
#! uvicorn config.asgi:application --host 0.0.0.0 --reload

{%- if cookiecutter.add_asgi.lower() == "y" %}
uvicorn config.asgi:application --host 0.0.0.0 --reload
{%- else %}
python manage.py runserver_plus 0.0.0.0:8000
{%- endif %}
9 changes: 6 additions & 3 deletions {{cookiecutter.github_repository}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ authors = ["{{cookiecutter.default_from_email}}"]

[tool.poetry.dependencies]
python = "~3.9"
Django = "~3.2.15"
Django = "~4.1"
django-environ = "^0.9"
django-sites = "^0.11"
django-filter = "^21.1"
argon2-cffi = "^21.3"
python-dotenv = "^0.21"
django-cors-headers = "^3.13"
{% if cookiecutter.enable_whitenoise.lower() == 'y' -%}
whitenoise = "^6.2"
whitenoise = "^6.4.0"
{%- endif %}

# Extensions
Expand All @@ -32,7 +32,7 @@ django-versatileimagefield = "^2.2"

# REST APIs
# -------------------------------------
djangorestframework = "3.13.1"
djangorestframework = "3.14"
drf-yasg = "^1.21"


Expand Down Expand Up @@ -78,6 +78,9 @@ django-mail-templated = "^2.6"
# Static Files and Media Storage
# -------------------------------------
gunicorn = "~20.1.0"
{%- if cookiecutter.add_asgi.lower() == "y" %}
uvicorn = "^0.21.0"
theskumar marked this conversation as resolved.
Show resolved Hide resolved
{%- endif %}
django-storages = "^1.13"
boto3 = "~1.26.47"

Expand Down