From e6b800d9854bb0956afd1df175501466faa5be2b Mon Sep 17 00:00:00 2001 From: Andrew-Chen-Wang Date: Tue, 24 Mar 2020 20:59:28 -0400 Subject: [PATCH] Added static files URL for runserver-level/best performance * The reason there was a degraded performance was because we're using Gunicorn itself as a local tester. So we needed to add the staticfiles urls --- {{cookiecutter.project_slug}}/config/urls.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/{{cookiecutter.project_slug}}/config/urls.py b/{{cookiecutter.project_slug}}/config/urls.py index 81860906..2cf7be95 100644 --- a/{{cookiecutter.project_slug}}/config/urls.py +++ b/{{cookiecutter.project_slug}}/config/urls.py @@ -7,6 +7,9 @@ from django.views.generic import TemplateView {%- if cookiecutter.use_drf == 'y' %} from rest_framework.authtoken.views import obtain_auth_token {%- endif %} +{%- if cookiecutter.use_async %} +from django.contrib.staticfiles.urls import staticfiles_urlpatterns +{%- endif %} urlpatterns = [ path("", TemplateView.as_view(template_name="pages/home.html"), name="home"), @@ -20,6 +23,11 @@ urlpatterns = [ path("accounts/", include("allauth.urls")), # Your stuff: custom urls includes go here ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +{% if cookiecutter.use_async %} +# Static file serving when using Gunicorn + Uvicorn for local development +if settings.DEBUG: + urlpatterns += staticfiles_urlpatterns() +{% endif %} {% if cookiecutter.use_drf == 'y' -%} # API URLS urlpatterns += [