简体   繁体   English

App Engine(Google Cloud)中我的 Django 应用程序中出现 500 服务器错误

[英]500 Server Error in my Django App in App Engine (Google Cloud)

I am new to Google Cloud an I followed the steps in https://cloud.google.com/python/django/appengine and deployed the App successfully.我是 Google Cloud 的新手,我按照https://cloud.google.com/python/django/appengine中的步骤成功部署了应用程序。 However, when I go to the page https://PROJECT_ID.REGION_ID.r.appspot.com the next message is displayed: However, when I go to the page https://PROJECT_ID.REGION_ID.r.appspot.com the next message is displayed:

Error: Server Error The server encountered an error and could not complete your request.错误:服务器错误 服务器遇到错误,无法完成您的请求。 Please try again in 30 seconds.请在 30 秒后重试。

I have seen this is something really usual but cannot find any useful solution.我已经看到这很常见,但找不到任何有用的解决方案。 I would appreciate any help.我将不胜感激任何帮助。


my settings.py:我的设置.py:

from pathlib import Path
import os
BASE_DIR = Path(__file__).resolve().parent.parent
SECRET_KEY = '…'
DEBUG = True
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [
    'KhalilApp.apps.KhalilappConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'DjangoServer.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'KhalilApp/templates'), os.path.join(BASE_DIR,'Mapilib')],
        '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 = 'DjangoServer.wsgi.application'

import pymysql  # noqa: 402
pymysql.version_info = (1, 4, 6, 'final', 0)  # change mysqlclient version
pymysql.install_as_MySQLdb()
if os.getenv('GAE_APPLICATION', None):
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': '/cloudsql/…’,
            'USER': 'maestros',
            'PASSWORD': '…',
            'NAME': 'principal',
        }
    }
else:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'HOST': '127.0.0.1',
            'PORT': '…',
            'NAME': 'principal',
            'USER': 'maestros',
            'PASSWORD': '…',
        }
    }
if os.getenv('TRAMPOLINE_CI', None):
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join(BASE_DIR, 'db.sqlite3')
        }
    }

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Europe/Madrid'
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
STATIC_ROOT = 'static'

You have errors in your code.您的代码中有错误。 500 Server Error means you have something wrong in your application. 500 Server Error 表示您的应用程序有问题。

If you want to configure gunicorn in App Engine Standard, please add the following line into your app.yaml file:如果您想在 App Engine Standard 中配置 gunicorn,请将以下行添加到您的 app.yaml 文件中:

entrypoint: gunicorn -b :$PORT main:app

You can check the following Documentation to add an entrypoint to start gunicorn that listens on the port specified by the PORT environment variable您可以查看以下文档以添加一个入口点来启动 gunicorn,该入口点侦听 PORT 环境变量指定的端口

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

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