Skip to content Skip to sidebar Skip to footer

Django Model: Valueerror: Missing Staticfiles Manifest Entry For "file_name.ext"

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 following model: fr

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

  1. (frontend / Django Templates option) {% static profile_instance.avatar_url %}, where profile_instance is a context variable referring to a Profile object.

  2. (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:

  1. collectstatic needs to run in order to create manifest.json

  2. your application needs to load in order to run manage.py commands, which calls static()

  3. static() relies on an entry in manifest.json to resolve.

Post a Comment for "Django Model: Valueerror: Missing Staticfiles Manifest Entry For "file_name.ext""