0

I am a newbie django developer and this is the django project i will be deploying. Everything works in development but I am been having issues in production. PS: I am using shared hosting for the deployment.

First, the website loads but images are not showing. I tried using whitenoise but keeps getting the error

 File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/home/publishm/PUBLISHMYCRAFT/learnwithjdd/index/urls.py", line 12, in <module>
    path('favicon.ico', RedirectView.as_view(url=staticfiles_storage.url('images/favicon_io/favicon.ico'))),  File "/home/publishm/virtualenv/PUBLISHMYCRAFT/learnwithjdd/3.9/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py",
 line 203, in url
    return self._url(self.stored_name, name, force)
  File "/home/publishm/virtualenv/PUBLISHMYCRAFT/learnwithjdd/3.9/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 182, in _url
    hashed_name = hashed_name_func(*args)
  File "/home/publishm/virtualenv/PUBLISHMYCRAFT/learnwithjdd/3.9/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 513, in stored_name
    raise ValueError(
ValueError: Missing staticfiles manifest entry for 'images/favicon_io/favicon.ico'

part of my urls.py

from . import views
from django.urls import path
from . views import  BlogHomeView, BlogDetailsView, AddPostView, EditPostView, DeletePostView, AddCategoryView, DraftsListView, AddDraftPostView, DraftPostDetailsView, EditDraftPostView, DeleteDraftPostView
from  django.views.generic.base import RedirectView
from django.contrib.staticfiles.storage import staticfiles_storage



app_name = 'index'

urlpatterns = [
    path('favicon.ico', RedirectView.as_view(url=staticfiles_storage.url('favicon.ico')))
]

part of the settings.py

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    "whitenoise.middleware.WhiteNoiseMiddleware",
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / "staticfiles"
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

I tried using the whitenoise and play around with the path but the static files and the ckeditor are not working. The error disppears and the website loads the the whitenoise is commented but the images files do not show as the static files are not rendered

Adewale
  • 23
  • 7

1 Answers1

0

things that comes to my mind:

1- make sure that you have fun the 'collectstatic' command before deploying your project. this command collect static files from all installed apps into the 'STATIC_ROOT' directory. if you haven't run this command run it:

python manage.py collectstatic

2- shared hosting environments may have specific server configurations lthat can affect the serving static files. make sure your hosting provider allows you to serve static files using django's static file handling and check for any restrictions

3- make sure your static files and directories have read permission on server

4- if you have some custom static files that are not part of the installed apps, you must defined them in your 'settings.py':

STATICFILES_DIRS =[ BASE_DIR / "your_custom_static_directory"]

5- double check your whitenoise configuration base on your django version, you can use this link: whitenoise_configuration

6- make sure that you set 'DEBUG = False' in your production

7- clear your browser cache

8- check your server logs for any error messages related to static file serving

if none of these solved your problem contact hosting provider support.

I hope this helps you.

Kiarash Gh
  • 166
  • 4