why when I set debug = false, then admin/ looks bad?

Hi everyone,

I’m creating a website and when I made a custom 404 Error Page, suddenly the css didn’t work for the admin page. Does anyone know how to fix this?

these are my settings and what I added to urls to make static work for html:

import os
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = 'django-insecure-48k(nnqsvq+#()(1d9jbti6mtjpzi8iw5hti*b_*dwm!hs=!v1'
DEBUG = False
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
    'me',
    'error',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]
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',
]
ROOT_URLCONF = 'page.urls'
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]
WSGI_APPLICATION = 'page.wsgi.application'
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}
AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

from django.contrib import admin
from django.urls import path, include
from django.conf.urls import handler404
from django.conf.urls.static import static
from django.conf import settings

handler404 = 'error.views.custom_404'

urlpatterns = [
    path('admin/', admin.site.urls),
    path("me/", include("me.urls"))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

The runserver command ignores static files by default when DEBUG = False.

Generally speaking, you want to use runserver in development only, and with DEBUG = True. In a production deployment environment, you never want to use runserver and you always want DEBUG = False.

See the docs for runserver, and How to manage static files (e.g. images, JavaScript, CSS) | Django documentation | Django

1 Like

I want to release my app into production, what should I do instead of running runserver

See the docs at How to deploy Django | Django documentation | Django

As I’ve said multiple times here:

Deploying a Django project into a production-quality environment is probably the most intricate and confusing thing you will ever do with Django - primarily because so little of it has anything to do with Django itself.

oh wow, I had a deadline in a day ro release the app into production, guess I’l getting fired :smiley:
thanks alot though, very helpful