Search code examples
pythondjangopythonanywhere

Admin css won't load when deploying Django project on pythonanywhere


So I had some trouble with static files when I tried deploying them... Thing is that I manage to server the main static files and everything is working except for the admin. I think maybe something is wrong with my configuration. Here is screenshot of my web: https://i.sstatic.net/rYxTm.png This is my settings.py:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))

TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates') STATIC_DIR = os.path.join(BASE_DIR, 'static') MEDIA_DIR = os.path.join(BASE_DIR, 'media')

SECRET_KEY = 'ie&_vj_d)t5itbpun3%58tlw(3=ptn1^5qj43kgm^&_z^!5('

DEBUG = False

ALLOWED_HOSTS = ['danielcirstea.pythonanywhere.com']

INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rango', 'registration' ]

MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', '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', 'django.middleware.locale.LocaleMiddleware' ]

ROOT_URLCONF = 'tango_with_django_project.urls'

TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [TEMPLATE_DIR, ], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'django.template.context_processors.media' ], }, }, ]

WSGI_APPLICATION = 'tango_with_django_project.wsgi.application'

LANGUAGE_CODE = 'ro'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATICFILES_DIRS = [STATIC_DIR, ] STATIC_URL = '/static/'

MEDIA_ROOT = MEDIA_DIR MEDIA_URL = '/media/'

REGISTRATION_OPEN = True ACCOUNT_ACTIVATION_DAYS = 7 REGISTRATION_AUTO_LOGIN = True LOGIN_REDIRECT_URL = '/rango/' LOGIN_URL = '/accounts/login/'


Solution

  • First things first -- the SECRET_KEY in your settings file is something you need to keep secret, and this post is publicly-visible, so you should change it now for safety.

    Regarding the admin CSS, the first line in your static files setup looks wrong -- I think the "URL" on that line should be /static/admin. If you change that and then reload the website from the "Web" page, the admin CSS should start working.