简体   繁体   English

Google App Engine Django App Admin登录原因502

[英]Google App Engine Django App Admin login causes 502

This App works great locally, but on App Engine it produces a 502 error. 该应用程序在本地运行良好,但在App Engine上会产生502错误。 I am using the same Google Cloud Postgres database in both environments. 我在两种环境中都使用相同的Google Cloud Postgres数据库。

The app deploys to appengine without errors, I can get to GET routes just fine, I can get to the Django Login screen just fine. 该应用程序已正确部署到appengine,我可以正常访问GET路由,也可以正常访问Django登录屏幕。

However, when I enter the SAME superuser I login with locally it throws a 502. 但是,当我输入SAME超级用户时,我在本地登录时会抛出502。

I've included some helper files below with redacted items in [] - some with info as to what is in the field in case I'm not sure I'm correct. 我在下面包括了一些帮助文件,这些文件的[]中有一些编辑过的项目-一些有关该字段中内容的信息,以防万一我不确定我是否正确。

Let me know what else might be helpful to post. 让我知道还有什么对发布有用。

settings.py 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()

I figured it out! 我想到了!

In case anyone else is in teh same boat... silly me had commented out the if statement that would automagically swap between host names... so I was trying to connect with teh IP rather than the magical connection string. 万一其他人都在同一条船上...愚蠢的我已经注释掉了会自动在主机名之间交换的if语句...所以我试图使用IP而不是神奇的连接字符串进行连接。

I feel silly :) 我觉得很傻:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM