![](/img/trans.png)
[英]Django gives “502 Bad Gateway” error on Google App Engine
[英]Google App Engine Django App Admin login causes 502
該應用程序在本地運行良好,但在App Engine上會產生502錯誤。 我在兩種環境中都使用相同的Google Cloud Postgres數據庫。
該應用程序已正確部署到appengine,我可以正常訪問GET路由,也可以正常訪問Django登錄屏幕。
但是,當我輸入SAME超級用戶時,我在本地登錄時會拋出502。
我在下面包括了一些幫助文件,這些文件的[]中有一些編輯過的項目-一些有關該字段中內容的信息,以防萬一我不確定我是否正確。
讓我知道還有什么對發布有用。
# mysite/settings.py
# 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__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = [redacted]
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
# SECURITY WARNING: App Engine's security features ensure that it is safe to
# have ALLOWED_HOSTS = ['*'] when the app is deployed. If you deploy a Django
# app not on App Engine, make sure to set an appropriate host here.
# See https://docs.djangoproject.com/en/1.10/ref/settings/
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp'
)
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 = 'mysite.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 = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
# [START dbconfig]
DATABASES = {
'default': {
# If you are using Cloud SQL for MySQL rather than PostgreSQL, set
# 'ENGINE': 'django.db.backends.mysql' instead of the following.
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'jcapp',
'USER': 'postgres',
'PASSWORD': '[redacted]',
'HOST': '[I set this to the URL of the appengine
instance... just
changed to 127.0.0.1 for testing]',
# For MySQL, set 'PORT': '3306' instead of the following. Any Cloud
# SQL Proxy instances running locally must also be set to tcp:3306.
'PORT': '5432',
}
}
# In the flexible environment, you connect to CloudSQL using a unix socket.
# Locally, you can use the CloudSQL proxy to proxy a localhost connection
# to the instance
# DATABASES['default']['HOST'] = '/cloudsql/jc-app-176715:us-east4:jc-app'
# if os.getenv('GAE_INSTANCE'):
# pass
# else:
# DATABASES['default']['HOST'] = '127.0.0.1'
# [END dbconfig]
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
# [START staticurl]
# Fill in your cloud bucket and switch which one of the following 2 lines
# is commented to serve static content from GCS
STATIC_URL = 'https://storage.googleapis.com/[gcs-bucket]/static/'
# local
# STATIC_URL = '/static/'
# [END staticurl]
STATIC_ROOT = 'static/'
# myapp/urls.py (works fine?)
# myapp/urls.py
# non-admin urls here
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
#project/urls.py
# mysite/urls.py
# admin URLs here
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [url(r'^', include('myapp.urls')),
url(r'^admin/', admin.site.urls),
url(r'^login/$', auth_views.login, name='login'),
url(r'^logout/$', auth_views.logout, name='logout'),
]
# This enables static files to be served from the Gunicorn server
# In Production, serve static files from Google Cloud Storage or an alternative
# CDN
# *** Do I need to comment this out? ***
if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
我想到了!
萬一其他人都在同一條船上...愚蠢的我已經注釋掉了會自動在主機名之間交換的if語句...所以我試圖使用IP而不是神奇的連接字符串進行連接。
我覺得很傻:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.