0

I have a python server running. And at the onset, it runs the application perfectly loading the images and scripts. If I leave it running for 24hrs, I discover that it gives a GET 400 error messages of not loading the images/scripts.

enter image description here I also observed that if I replace all the applications altogether with the backup, then it likely starts running perfectly again.

My settings.py:

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/


ALLOWED_HOSTS = ['*']


# Application definition

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

    'uploads.core',

]

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

ROOT_URLCONF = 'uploads.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'uploads/templates'),],
        '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 = 'uploads.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators

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',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Taiwotman
  • 885
  • 14
  • 27
  • Your question is not answerable. What is the command you use to start your "server"? – Paul Collingwood Aug 12 '17 at 12:56
  • Side note: *keep the secret key used in production secret!* – Moses Koledoye Aug 12 '17 at 13:00
  • @PaulCollingwood python manage.py runserver 0.0.0.0.8000 – Taiwotman Aug 12 '17 at 13:42
  • @MosesKoledoye I removed it. Thanks. – Taiwotman Aug 12 '17 at 13:43
  • https://serverfault.com/questions/717568/risks-of-using-django-manage-py-runserver-for-production-in-a-small-scale-server – Paul Collingwood Aug 12 '17 at 15:52
  • @PaulCollingwood but I am still not clear about this. Why running the server for a long time would result in 'NOT FOUND' for the images and scripts with GET 400 error. Is there a walk around this?Thanks. – Taiwotman Aug 12 '17 at 19:41
  • *DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. * so sayeth the link and there is the answer. If you find out why it fails you can submit a patch to the project and help it stay up for longer :) but who knows. Look into https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/gunicorn/ – Paul Collingwood Aug 12 '17 at 21:44
  • I finally got the right answer: [enter link description here](https://stackoverflow.com/questions/22700097/how-to-point-correctly-to-static-image-in-django) Credit to @4dgaurav – Taiwotman Aug 14 '17 at 00:10

1 Answers1

0

I finally got the right answer: how to point correctly to static image in django

Credit to @4dgaurav

Taiwotman
  • 885
  • 14
  • 27