cookiecutter-django
cookiecutter-django copied to clipboard
Selecting Whitenoise and AWS as cloud provider overrides STATIC_URL in a way that assumes Collectfast
What happened?
I had selected Whitenoise as my static asset solution, but also chose AWS as my cloud provider. This is because I want to use Whitenoise for static assets, but AWS for uploaded media. But essentially, these two selections halfway implemented Collectfast with AWS, but did not fully make the solution work. Neither Whitenoise or Cloud static assets worked when both are selected.
What should've happened instead?
If Whitenoise is selected, AWS should only apply to media instead of static assets. Or, alternatively, by choosing AWS, it should also setup Collectfast so that this solution works. By choosing both Whitenoise and AWS, static asset generation is completely broken.
By choosing both, this is what production.py settings are generated:
# STATIC & MEDIA
# ------------------------
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
MEDIA_URL = f"https://{aws_s3_domain}/media/"
COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy"
STATIC_URL = f"https://{aws_s3_domain}/static/"
But Collectfast is not installed because Whitenoise was selected.
Additional details
-
Host system configuration:
- Cookiecutter 2.5.0
- This was found on a Heroku deployment when static assets were not working correctly.
- Python 3.11.4
{
"cookiecutter": {
"project_name": "Project",
"project_slug": "project_slug",
"description": "This project is a website.",
"author_name": "Jason",
"domain_name": "example.com",
"email": "[email protected]",
"version": "0.1.0",
"open_source_license": "Not open source",
"username_type": "email",
"timezone": "UTC",
"windows": "n",
"editor": "VS Code",
"use_docker": "n",
"postgresql_version": "12",
"cloud_provider": "AWS",
"mail_service": "Mailgun",
"use_async": "n",
"use_drf": "y",
"frontend_pipeline": "Gulp",
"use_celery": "n",
"use_mailpit": "n",
"use_sentry": "y",
"use_whitenoise": "y",
"use_heroku": "y",
"ci_tool": "Github",
"keep_local_envs_in_vcs": "y",
"debug": "n",
"_template": "gh:cookiecutter/cookiecutter-django",
"_output_dir": "/Users/jason/Sites",
"_repo_dir": "/Users/jason/.cookiecutters/cookiecutter-django",
"_checkout": null
}
Sounds like a bug indeed, agree that it is not expected. Would you like to send us a pull request to fix it?
Hit this issue also, should be easy to fix.
I created a PR for this issue, since I ran into the same problem. Would be nice if someone could have a look :)