Before you mark it as duplicate, I have read ValueError: Missing staticfiles manifest entry for \'favicon.ico\' , and it does not solve my problem.
I have the follow
You can circumvent this issue and improve the code by moving the static()
call out of the model field and changing the default value to the string "pledges/images/no-profile-photo.png"
. It should look like this:
avatar_url = models.URLField(default='pledges/images/no-profile-photo.png')
When you access avatar_url
, use either
(frontend / Django Templates option) {% static profile_instance.avatar_url %}
, where profile_instance
is a context variable referring to a Profile object.
(backend / Python option) use static(profile_instance.avatar_url)
.
By using the result of static()
for a default value, the app is putting a URL in the database that includes the STATIC_URL
prefix -- which is like hard-coding it because data won't change when settings.py
does. More generally, you shouldn't store the results of static()
in the database at all.
If you ensure that you're using the {% static %}
tag or static()
function each time you're accessing avatar_url
for display on the frontend, STATIC_URL
will still be added based on your environment config at runtime.
This SO thread has a lot of good content on staticfiles
It looks like you have a circular dependency:
collectstatic
needs to run in order to create manifest.json
your application needs to load in order to run manage.py
commands, which calls static()
static()
relies on an entry in manifest.json
to resolve.