0

I logged in via ssh to my Linux Gentoo server and tried to run my python3.7 django code with "python3.7 manage.py runserver". When I tried to visit the website with my chrome browser on "127.0.0.1:8000" I get the same message like when I didn't ran the "runserver"-command. When I ran the code on my laptop, everything worked fine!

My settings.py code is:

"""
Django settings for ProjectCappuchino project.

Generated by 'django-admin startproject' using Django 2.2.3.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""

import os
from django.urls import reverse_lazy

# 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/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'XXXX'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


LOGIN_REDIRECT_URL=reverse_lazy('dashboard')
LOGIN_URL = reverse_lazy('login')
LOGOUT_URL= reverse_lazy('logout')

SESSION_COOKIE_AGE = 60 * 60 * 8


# Application definition

INSTALLED_APPS = [
    'capchine',
    'crispy_forms',
    'bootstrapform',

    'django.contrib.humanize',
    '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 = 'ProjectCappuchino.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 = 'ProjectCappuchino.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/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/2.2/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/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

#TIME_ZONE = 'UTC'
TIME_ZONE = 'Europe/Berlin'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

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

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

Could it be, that there are some firewall issues or sth from the server? It is a managed server btw...

Janiii
  • 9
  • 1
  • Are you under root? And try run server with another port – Pavel Antspovich Oct 17 '19 at 19:02
  • 2
    Hang on, where are you using the browser? If you've ssh-ed into your server you can't be running the browser there, so you must be doing it on your own machine. So why would you use the localhost address rather than the actual IP of your server? – Daniel Roseman Oct 17 '19 at 19:08
  • Not sure if this is the cause of your issue, but you need to add your hostname to `ALLOWED_HOSTS` – Lord Elrond Oct 17 '19 at 19:10
  • Where are you setting the port to 8000? I don't see it anywhere in your setup here. – David Culbreth Oct 17 '19 at 19:25
  • @DanielRoseman: When I type in my domain adress, it is still not working. – Janiii Oct 17 '19 at 19:28
  • @DavidCulbreth: I thought, port 8000 is the default port when running just "runserver" – Janiii Oct 17 '19 at 19:29
  • @DanielRoseman Thank you for your answers! When I pasted ther server IP adress into "allowed host" in the settings.py and run the command "python manage.py runserver 0.0.0.0:8000" and try to open the IP adress of my server +":8000" via chrome I will receive an "ERR_EMPTY_RESPONSE" and it is still not working. – Janiii Oct 19 '19 at 14:48

0 Answers0