同时,django将抛出301错误:
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
我已成功将应用程序部署到Heroku(所有URL都在那里工作),但我无法在本地计算机上运行它.我也尝试过heroku本地包含的dev服务器同样的效果.
作为参考我的django urls.py文件看起来像:
from django.conf.urls import urlfrom django.contrib import adminfrom 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),]
任何帮助赞赏!
编辑:
发布Settings.py
import osimport 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'# LogsLOGGING = { '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)# Redisredis_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 = 60broKER_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 = 300CELERYD_MAX_TASKS_PER_CHILD = 2broKER_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解决方法 OP在最初的问题’评论中发布了解决方案,但他/她似乎忘记将其作为一个发布者发布.所以这里是:
总结Ok so the problem is because of the https,thus getting redirected,as localhost is working on http,try to comment out this line and check SECURE_PROXY_SSL_header = (‘http_X_FORWARDED_PROTO’,‘https’) and also comment out the sslify from mIDdleware as saID by @ShobhitSharma
以上是内存溢出为你收集整理的python – 为什么我不能连接到我的localhost django dev服务器?全部内容,希望文章能够帮你解决python – 为什么我不能连接到我的localhost django dev服务器?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)