Django Model: Valueerror: Missing Staticfiles Manifest Entry For "file_name.ext"
Solution 1:
Answer :
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 %}, whereprofile_instanceis a context variable referring to a Profile object.(backend / Python option) use
static(profile_instance.avatar_url).
Explanation:
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
Why the error is happening:
It looks like you have a circular dependency:
collectstaticneeds to run in order to createmanifest.jsonyour application needs to load in order to run
manage.pycommands, which callsstatic()static()relies on an entry inmanifest.jsonto resolve.
Post a Comment for "Django Model: Valueerror: Missing Staticfiles Manifest Entry For "file_name.ext""