I'm trying to deploy my website in pythonanywhere.com following djangoGirls tutorial.
When I run my website, It give me this error:
Error running WSGI application
ImportError: No module named 'whitenoise'
File "/var/www/cryptoassistant_pythonanywhere_com_wsgi.py", line 7, in module>
from whitenoise.django import DjangoWhiteNoise
My WGSI file:
import os
import sys
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(get_wsgi_application())
path = '/home/cryptoassistant/tfg/'
if path not in sys.path:
sys.path.append(path)
and my setting.py file:
MIDDLEWARE_CLASSES = (
'django.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
I installed whitenoise
$ pip install whitenoise
> Requeriment already satisfied: whitenoise in path (3.3.1)
What I should change?
edit
I installed freeze and my requirements:
-f /usr/share/pip-wheels
Django==1.8
freeze==1.0.10
six==1.11.0
whitenoise==3.3.1
If you use virtual environment, check(command : pip freeze) if whitenoise is installed. If yes, you can add below details to your settings.py to work.
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
# ...
]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'staticfiles')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
# '/var/www/static/',
]
Verify/ Update your static setttings as stated above.
Next, make sure DEBUG=True and run, the collectstatic command.
To see if any errors, run makemigrations and migrate command. You should be good