S
S
Sergey Nizhny Novgorod2016-02-13 13:49:20
Django
Sergey Nizhny Novgorod, 2016-02-13 13:49:20

How to fix error in Django: The requested URL / was not found on this server?

Good afternoon. I installed a django project on my VPS
according to this instruction .
The instructions describe the bare installation method, but I added the 3.4.3 version of python to the environment and copied the entire project via FTP.
What I have:
1) Database working:
- makemigrations, migrate, collectstatic, runsever - everything works.

STATIC_URL = '/static/' #Сама папка лежит в корне, и стили работают на кастомной 404 странице. т.е. все вроде верно.
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATICFILES_DIRS = (
)

2) When I try to go to any page, I get the error "Not Found. The requested URL / was not found on this server", or I throw a custom 404 page into the root folder, I get it.
DEBUG = False

ALLOWED_HOSTS = ['*',]

3) Jungi admin works correctly. Posts without pictures are added, if I try to add a picture I get a 500 error.
Pillow and its packages are installed correctly. If they were not, then I would not be able to do the base migration.
4) The Nginx log is silent and does not show anything on this account.
I have a feeling that somehow I didn't register my applications with Django for this machine (the settings.py file has them, of course), so it refuses to see them. If you run the project locally via PyCharm, then all urls are correct and work correctly.
____
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os

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


SECRET_KEY = 'xxx'

DEBUG = False

ALLOWED_HOSTS = [
    '*',
    ]


EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.yandex.ru'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'xxx'
EMAIL_HOST_PASSWORD = 'xxx'
DEFAULT_FROM_EMAIL = 'xxx'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'



# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'bakot',
    'loginsys',
)

MIDDLEWARE_CLASSES = (
    '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',
)

ROOT_URLCONF = 'apifolder.urls'

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


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'xxx',
        'USER': 'xxx',
        'PASSWORD': 'xxx',
        'HOST': 'localhost',
        'PORT': '',
    }
}


LANGUAGE_CODE = 'ru-ru'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, "static")
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
STATICFILES_DIRS = (
)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Voronkov, 2016-02-16
@DmitryVoronkov

Pillow and its packages are installed correctly. If they were not, then I would not be able to do the base migration.

sudo apt-get install libjpeg-dev
pip install --no-cache-dir -I pillow

Nginx won't show anything. Set up logging in the project itself, in settings.py
Otherwise, you need to look at the settings.py file.

Владислав Скляр, 2017-01-13
@VladSkliar

Попробуйте заменить настройки

STATIC_ROOT = os.path.join(BASE_DIR, 'collect_static/')

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

STATIC_URL = '/static/'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

MEDIA_URL = '/media/'

Ну или работай со статикой через nginx, вот годный туториал по деплою джанги, там есть раздача статики и медиа файлов
Link

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question