Google App Engine Django App Admin登录导致502

时间:2017-08-13 20:50:37

标签: python django postgresql google-app-engine authentication

此应用程序在本地运行良好,但在App Engine上它会产生502错误。我在两种环境中都使用相同的Google Cloud Postgres数据库。

应用程序部署到appengine没有错误,我可以很好地获得GET路由,我可以很好地进入Django登录屏幕。

但是,当我输入SAME超级用户时,我在本地登录时会抛出502。

我在[]中包含了一些帮助文件,其中包含了[]中的编辑项目 - 有些文件包含了该字段中的内容,以防我不确定我是否正确。

让我知道还有什么可能有助于发布。

settings.py

# 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()

1 个答案:

答案 0 :(得分:0)

我明白了!

如果有其他人在同一条船上......愚蠢的我已经注释掉了会在主机名之间自动交换的if语句......所以我试图用IP而不是神奇的连接字符串连接。 / p>

我觉得很傻:)