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

How to purge thumbnails (and other static files) with whitenoise? #92

Closed
enoren5 opened this issue Mar 21, 2021 · 6 comments
Closed

How to purge thumbnails (and other static files) with whitenoise? #92

enoren5 opened this issue Mar 21, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@enoren5
Copy link
Owner

enoren5 commented Mar 21, 2021

When adding a thumbnail for a generator, K0.jpg (“The Fool”) and K21.jpg (“The World”) are getting renamed with a small hash appended to the end which causes Django to serve an empty thumbnail. I understand that the reason why is because inside the /static/img/thumbnails directory there is a duplicate thumbnail already named K0.jpg and K21.jpg. . The solution locally is to manually enter the thumbnails directory and delete all the duplicate K0.jpg and K21.jpg’s (including the ones with the hashes) and then locate the generator inside the Admin Dashboard and re-upload it. However in production on Heroku in the cloud, the static directory is delegated out to whitenoise which is a wrapper to integrate static files hosted on AWS. So I can’t selectively delete static files.

In the context of Heroku and AWS, how do I manually remove duplicate thumbnail static files?

@enoren5 enoren5 added the bug Something isn't working label Mar 21, 2021
@UmarGit
Copy link
Contributor

UmarGit commented Mar 30, 2021

In the context of Heroku and AWS, how do I manually remove duplicate thumbnail static files?

@enoren5 brother follow the steps:

To delete the duplicate or hashed files, we can remove them by running the command.

python manage.py collectstatic --noinput --clear --no-post-process

--noinput Do NOT prompt the user for input of any kind

--clear Clear the existing files before trying to copy or link the original file

--no-post-process Don’t call the post_process() method of the configured STATICFILES_STORAGE storage backend

@enoren5
Copy link
Owner Author

enoren5 commented Mar 30, 2021

Thanks, Umar! Sounds great. Here is some output from my shell:

(local venv) $ heroku ps:exec --app tarot-prod
Establishing credentials... done
Connecting to web.1 on ⬢ tarot-prod... 

(heroku) $ python manage.py collectstatic --noinput --clear --no-post-process
Mode:  Not Secure
Database Config:  {'default': {'NAME': '/app/db.sqlite3', 'USER': '', 'PASSWORD': '', 'HOST': '', 'PORT': '', 'CONN_MAX_AGE': 600, 'ENGINE': 'django.db.backends.sqlite3'}}
246 static files copied to '/app/staticfiles', 616 post-processed.

Deleting 'staticfiles.json'
Deleting 'db/generators_iter1.61034fc889bd.csv'
Deleting 'db/generators_iter1.csv.gz'
Deleting 'db/generators_iter1.61034fc889bd.csv.gz'
Deleting 'db/generators_iter1.csv'
Deleting 'css/all.012609b87d27.css'
...

The command proceeds to delete all of my static files.

I'm not sure how to test this because as you can see the 'Database Config' indicates db.sqlite3 instead of Postgres. So it appears that in order to determine if the command you suggest to correct this static file issue #92, first we need to continue to resolve Issue #83.

Thanks for your hardwork so far, @UmarGit.

@UmarGit
Copy link
Contributor

UmarGit commented Apr 1, 2021

hmm

@enoren5, okay brother let me check

@enoren5
Copy link
Owner Author

enoren5 commented Apr 9, 2021

I initially believed that the problem was with static files (thumbnails) hosted in the cloud via S3. But actually the problem (and solution) involves purging tarot key thumbnails locally - - if you can believe that! First navigate to tarot_juicer/static/img/thumbnail/ in your file explorer. Delete the instances of K20.jpg along with K20_<hash>.jpg (or other problem thumbnails). Next, while logged in to the Django Admin Dashboard, re-upload the thumbnail from scratch for each generator. As a result, when revealing the tarot card album, all the missing thumbnails should be cleared!

Thanks @UmarGit. You have resolved the Issue described originally.

@enoren5 enoren5 closed this as completed Apr 9, 2021
@enoren5
Copy link
Owner Author

enoren5 commented May 14, 2021

I’m re-opening this issue because other static files are still not loading properly. This time the problem file is with the gateway.css file when Django serves the gateway.html template. The problem is in production and not in the local test environment. Right now, the header in the template refers to the css file as: href="/static/css/gateway.995bb7957e7d.css". That hash needs to be removed. I tried running this locally: (venv) $ python manage.py collectstatic --noinput --clear --no-post-process as suggested above (which was supposed to resolve the original static file issue). I ran that command which deleted all the duplicate static files. I committed the changes to git locally. I then pushed to GitHub and Heroku. Then my production Django environment was serving a 500 error. So I rolled back the commit to the last known good state. Here is what remains outstanding:

  • The gateway.css static file needs to load properly.
  • This question needs to be answered: Django projects are designed to have only one static file directory tracked by developers on git. What was the rationale for deciding to track both static file directories? I asked about this on the Django forums and one member indicated: “I would offer the opinion that if you “needed” to track your collectstatic target directory within git, you’re probably doing something wrong.” How come my project tracks two static file directories? How do we get this tarot_juicer project to only track one static files directory?

https://forum.djangoproject.com/t/tracking-two-static-file-directories-or-just-one/7732

@enoren5 enoren5 reopened this May 14, 2021
@enoren5
Copy link
Owner Author

enoren5 commented Jun 15, 2021

Resolved in PR #119 with documented explanation in README.md (commit 6b05562).

@enoren5 enoren5 closed this as completed Jun 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants