Why cant I connect to my localhost django dev server?

2024/11/16 21:52:46

I'm creating a django app and in the process of setting up my local test environment. I can successfully get manage.py runserver working but pointing my browser to any variation of http://127.0.0.1:8000/, http://0.0.0.0:8000/, or http://localhost:8000/ returns a "This site can’t be reached" error.

Simultaneously, django will throw a 301 error:

Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[11/Jul/2017 23:35:37] "GET / HTTP/1.1" 301 0

I've successfully deployed the app to Heroku (all URLs work there), but I can't get it running on my local machine. I've also tried heroku local's included dev server to the same effect.

For reference my django urls.py file looks like:

from django.conf.urls import url
from django.contrib import admin
from recs.views import Request1, Check1, indexurlpatterns = [url(r'^$', index, name='index'),url(r'^admin/', admin.site.urls),url(r'^analyze1/', Request1),url(r'^analyze1/status/', Check1),
]

Any help appreciated!

Edit: Posting Settings.py

import os
import recs.environment_vars as e_v# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'KEY HIDDEN'# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')ALLOWED_HOSTS = ['*']# Application definitionINSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','recs',
]MIDDLEWARE_CLASSES = ['sslify.middleware.SSLifyMiddleware','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 = 'recs.urls'TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates','DIRS': ['recs/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',],},},
]WSGI_APPLICATION = 'recs.wsgi.application'# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases# Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/LANGUAGE_CODE = 'en-us'TIME_ZONE = 'America/Los_Angeles'USE_I18N = TrueUSE_L10N = TrueUSE_TZ = True# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, './static'),
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'# Logs
LOGGING = {'version': 1,'disable_existing_loggers': False,'formatters': {'verbose': {'format': ('Application Log: ' + '[%(levelname)s] %(asctime)s [%(process)d] ' +'pathname=%(pathname)s lineno=%(lineno)s ' +'funcname=%(funcName)s %(message)s'),'datefmt': '%Y-%m-%d %H:%M:%S'},'simple': {'format': '%(levelname)s %(message)s'}},'handlers': {'console': {'level': 'DEBUG','class': 'logging.StreamHandler','formatter': 'verbose'}},'loggers': {'clothing_recommendation.clothing_recommendation': {'handlers': ['console'],'level': 'DEBUG'}}
}import urlparse
# Celery + Redis - For long-lived asynchronous tasks (e.g. email parsing)
# Redis
redis_url = urlparse.urlparse(os.environ.get('REDIS_URL'))
CACHES = {"default": {"BACKEND": "redis_cache.RedisCache","LOCATION": "{0}:{1}".format(redis_url.hostname, redis_url.port),"OPTIONS": {"PASSWORD": redis_url.password,"DB": 0,}}
}# Celery
#CELERYD_TASK_SOFT_TIME_LIMIT = 60
BROKER_URL=os.environ['REDIS_URL']
CELERY_RESULT_BACKEND=os.environ['REDIS_URL']
CELERY_ACCEPT_CONTENT=['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_RESULT_EXPIRES = 300
CELERYD_MAX_TASKS_PER_CHILD = 2
BROKER_TRANSPORT_OPTIONS = {'confirm_publish': True} # Hack to prevent failed 'success' of tasks, per MT's experience with RabbitMQ - probably doesnt work with Redis? But worth trying
Answer

The OP posted the solution in the original question' comments but he/she seem to have forgotten to post it as an aswer. So here it is:

Ok so the problem is because of the https, thus getting redirected, aslocalhost is working on http, try to comment out this line and checkSECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') and alsocomment out the sslify from middleware as said by @ShobhitSharma

https://en.xdnf.cn/q/71624.html

Related Q&A

How to use L2 pooling in Tensorflow?

I am trying to implement one CNN architecture that uses L2 pooling. The reference paper particularly argues that L2 pooling was better than max pooling, so I would like to try L2 pooling after the acti…

Abstract base class is not enforcing function implementation

from abc import abstractmethod, ABCMetaclass AbstractBase(object):__metaclass__ = ABCMeta@abstractmethoddef must_implement_this_method(self):raise NotImplementedError()class ConcreteClass(AbstractBase)…

Create dataframe from dictionary of list with variable length

I have a dictionary of list which is like - from collections import defaultdict defaultdict(list,{row1: [Affinity],row2: [Ahmc,Garfield,Medical Center],row3: [Alamance,Macbeth],row4: [],row5: [Mayday]}…

How to standardize ONE column in Spark using StandardScaler?

I am trying to standardize (mean = 0, std = 1) one column (age) in my data frame. Below is my code in Spark (Python):from pyspark.ml.feature import StandardScaler from pyspark.ml.feature import VectorA…

Pandas Dataframe - select columns with a specific value in a specific row

I want to select columns with a specific value (say 1) in a specific row (say first row) for Pandas Dataframe

PermissionError: [Errno 13] Permission denied in Django

I have encountered a very strange problem.Im working with django, I create a directory on server, and try to save pickle file into it, this way:with open(path, wb) as output: pickle.dump(obj, output, p…

Evaluating Jacobian at specific points using sympy

I am trying to evaluate the Jacobian at (x,y)=(0,0) but unable to do so. import sympy as sp from sympy import * import numpy as np x,y=sp.symbols(x,y, real=True) J = Function(J)(x,y) f1=-y f2=x - 3*y*(…

PyAudio cannot find any output devices

When I run:import pyaudio pa = pyaudio.PyAudio() pa.get_default_output_device_info()I get:IOError: No Default Output Device AvailableWhen I say:pa.get_device_count()It returns 0L.And of course if I lis…

How do I write a Hybrid Property that depends on a column in children relationship?

Lets say I have two tables (using SQLAlchemy) for parents and children:class Child(Base):__tablename__ = Childid = Column(Integer, primary_key=True) is_boy = Column(Boolean, default=False)parent_id = C…

Python insert a line break in a string after character X

What is the python syntax to insert a line break after every occurrence of character "X" ? This below gave me a list object which has no split attribute error for myItem in myList.split…