2017-06-19 103 views
0

我试图在我的Ubuntu虚拟机上运行朋友的Django项目,但我无法访问开发服务器。 经过:访问开发服务器 - Django

python manage.py runserver 0:80 --settings=a.settings.dev_a 

下面的结果:

Performing system checks... 

System check identified no issues (0 silenced). 
June 19, 2017 - 21:56:31 
Django version 1.11, using settings 'a.settings.dev_a' 
Starting Channels development server at http://0:80/ 
Channel layer default (asgi_redis.core.RedisChannelLayer) 
Quit the server with CONTROL-C. 
2017-06-19 21:56:31,242 - INFO - worker - Listening on channels chat-messages, http.request, websocket.connect, websocket.disconnect, websocket.receive 
2017-06-19 21:56:31,247 - INFO - worker - Listening on channels chat-messages, http.request, websocket.connect, websocket.disconnect, websocket.receive 
2017-06-19 21:56:31,269 - INFO - worker - Listening on channels chat-messages, http.request, websocket.connect, websocket.disconnect, websocket.receive 
2017-06-19 21:56:31,289 - INFO - worker - Listening on channels chat-messages, http.request, websocket.connect, websocket.disconnect, websocket.receive 
2017-06-19 21:56:31,297 - INFO - server - Using busy-loop synchronous mode on channel layer 
Using busy-loop synchronous mode on channel layer 
2017-06-19 21:56:31,305 - INFO - server - Listening on endpoint tcp:port=80:interface=0 
Listening on endpoint tcp:port=80:interface=0 

而且,这里的DEV_A设置文件

from a.settings.base import * 
import sys 

SETTING = 'dev' 

SITE = 'http://a.local' 

DEBUG = True 

INTERNAL_IPS = ['127.0.0.1'] 

WSGI_APPLICATION = 'a.wsgi.dev_jeb.application' 

MEDIA_ROOT = '/a/media/' 
MEDIA_URL = '/media/' 

PROJECT_DIRECTORY = '/a' 

# The region to connect to when storing files. 
AWS_REGION = "eu-central-1" 
# The AWS access key used to access the storage buckets. 
AWS_ACCESS_KEY_ID = "AKIAJHTJIZI3IT2MWQ4A" 
# The AWS secret access key used to access the storage buckets. 
AWS_SECRET_ACCESS_KEY = "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" 
# The S3 bucket used to store uploaded files. 
AWS_S3_BUCKET_NAME = "a.test.media" 
# The S3 addressing style to use to connect to the bucket ("auto", "path" and "virtual"). 
AWS_S3_ADDRESSING_STYLE = "auto" 
# The endpoint to connect to (only needed if you are using a non-AWS provider) 
AWS_S3_ENDPOINT_URL = "" 
# A prefix to add to the start of all uploaded files. 
AWS_S3_KEY_PREFIX = "" 
# Whether to enable querystring authentication for uploaded files. 
AWS_S3_BUCKET_AUTH = True 
# The expire time used to access uploaded files. 
AWS_S3_MAX_AGE_SECONDS = 60*60 # 1 hour. 
# A custom URL prefix to use for public-facing URLs for uploaded files. 
AWS_S3_PUBLIC_URL = "" 
# Whether to set the storage class of uploaded files to REDUCED_REDUNDANCY. 
AWS_S3_REDUCED_REDUNDANCY = False 
# A dictionary of additional metadata to set on the uploaded files. 
# If the value is a callable, it will be called with the path of the file on S3. 
AWS_S3_METADATA = {} 
# Whether to enable gzip compression for uploaded files. 
AWS_S3_GZIP = True 

DEFAULT_FILE_STORAGE = "django_s3_storage.storage.S3Storage" 

# DEBUG TOOLBAR 
INSTALLED_APPS += [ 
    'debug_toolbar', 
    # 'channels_panel', 
] 
MIDDLEWARE += [ 
    'debug_toolbar.middleware.DebugToolbarMiddleware', 
] 

DEBUG_TOOLBAR_PANELS = [ 
    'debug_toolbar.panels.versions.VersionsPanel', 
    'debug_toolbar.panels.timer.TimerPanel', 
    'debug_toolbar.panels.settings.SettingsPanel', 
    'debug_toolbar.panels.headers.HeadersPanel', 
    'debug_toolbar.panels.request.RequestPanel', 
    'debug_toolbar.panels.sql.SQLPanel', 
    'debug_toolbar.panels.staticfiles.StaticFilesPanel', 
    'debug_toolbar.panels.templates.TemplatesPanel', 
    'debug_toolbar.panels.cache.CachePanel', 
    'debug_toolbar.panels.signals.SignalsPanel', 
    'debug_toolbar.panels.logging.LoggingPanel', 
    'debug_toolbar.panels.redirects.RedirectsPanel', 
    # 'channels_panel.panel.ChannelsDebugPanel', 
] 


# 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'), 
    # } 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql_psycopg2', 
     'NAME': 'a', 
     'USER': 'a_pg_admin', 
     'PASSWORD': '*********', 
     'HOST': 'localhost', 
     'PORT': '5432', 
    } 
} 

#Cross-domains cookies 
SESSION_COOKIE_DOMAIN = "a.local" 

ALLOWED_HOSTS = [ 
    'a.local', # Allow domain 
    'a.local.', # Also allow FQDN 
] 

STATIC_URL = '/static/' 

# EMAILS 
ANYMAIL = { 
    "MAILGUN_API_KEY": "******************************", 
    "MAILGUN_SEND_DEFAULTS": { 
     "esp_extra": {"sender_domain": "a.com"} 
     # 
    } 
} 

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' 
# EMAIL_BACKEND = "anymail.backends.mailgun.EmailBackend" 

# PAYPLUG 
PAYPLUG_SECRET_KEY = '********************************' 
LOGGING = { 

    'version': 1, 

    'handlers': { 

     'console': { 

      'class': 'logging.StreamHandler', 

      'stream': sys.stdout, 

     } 

    }, 

    'root': { 

     'handlers': ['console'], 

     'level': 'INFO' 

    } 

} 

# CHANNELS 
CHANNEL_LAYERS = { 
    "default": { 
     "BACKEND": "asgi_redis.RedisChannelLayer", 
     "CONFIG": { 
      "hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')], 
     }, 
     "ROUTING": "back.routing.channel_routing", 
    }, 
} 

我试图

localhost:8000 
http://0:80/ 
http://a.local 
localhost:6379 

但这一切工作。你有好主意吗 ?

+0

尝试'蟒蛇manage.py runserver命令--settings = a.settings。 dev_a'和你的服务器应该运行在'localhost:8000' – doru

+0

已经完成,但就像我说它不起作用 –

+1

你在哪里看到这种语法? “0”不是有效的IP地址。改为使用'0.0.0.0:80'。你是否以root身份运行?普通用户不能绑定到端口1024或更低端口。 – Chris

回答

0

增加 'localhost' 的,以ALLOWED_HOSTS在 “DEV_A” 文件

然后像说@FlipperPA,尝试

python manage.py runserver [::]:8000 --settings=a.settings.dev_a 
+0

就是这样!有用 !谢谢 –