0

有人可以帮我将 django 应用程序转换为 Google App Engine (GAE) 吗?我想成为 abel 将我的 django 应用程序中的所有文件复制到 GAE 应用程序。但是,我不确定应该如何配置 GAE 的默认文件。main.py 文件的外观应该如何才能像设计的那样运行 django 应用程序:

主文件

import webapp2

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('Hello world!')

app = webapp2.WSGIApplication([
    ('/', MainHandler)
], debug=True)

应用程序.yaml

application: appname
version: 1
runtime: python27
api_version: 1
threadsafe: true

libraries:
- name: django
  version: "1.3"

builtins:
- django_wsgi: on
4

1 回答 1

0

我有一个在应用程序引擎上运行的 django 应用程序。我按照此链接启动并运行它。http://www.allbuttonspressed.com/projects/djangoappengine。与常规 django 相比,所有配置文件都有很多小的变化。我现在不使用 django,因为我喜欢应用程序引擎并且讨厌 django。以下是我的一些文件示例。请注意,在您的问题中,您有一个 webapp2 请求处理程序,您不会在 django 中使用类似的东西。它将所有普通视图定义为函数,而不是像应用引擎这样的类。如果您决定尝试这种方法,请告诉我它是如何进行的。

在我点击上面的链接之后,这就是我的 app.yaml。

application: app
version: production
runtime: python27
api_version: 1
threadsafe: yes

libraries:
- name: django
  version: latest


handlers:
- url: /_ah/queue/deferred
  script: djangoappengine.deferred.handler.application
  login: admin

- url: /_ah/stats/.*
  script: djangoappengine.appstats.application

- url: /.*
  script: djangoappengine.main.application

我的设置.py

# Initialize App Engine and import the default settings (DB backend, etc.).
# If you want to use a different backend you have to remove all occurences
# of "djangoappengine" from this file.
from djangoappengine.settings_base import *
import os

DEBUG = False

TEMPLATE_DEBUG = DEBUG

# Activate django-dbindexer for the default database
DATABASES['native'] = DATABASES['default']
DATABASES['default'] = {'ENGINE': 'dbindexer', 'TARGET': 'native'}
AUTOLOAD_SITECONF = 'indexes'

INSTALLED_APPS = (

    'django.contrib.contenttypes',
    'django.contrib.auth',
    'django.contrib.sessions',
    'djangotoolbox',
    'autoload',
    'dbindexer',

    # djangoappengine should come last, so it can override a few manage.py commands
    'djangoappengine',
    )

MIDDLEWARE_CLASSES = (
    # This loads the index definitions, so it has to come first
    'autoload.middleware.AutoloadMiddleware',

    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    )

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.request',
    'django.core.context_processors.media',
    'context_processors.general'
    )


ADMIN_MEDIA_PREFIX = '/media/'
TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates'),
    os.path.join(os.path.dirname(__file__), 'media'),

    )

主文件

import os,sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

from google.appengine.dist import use_library
use_library('django', '1.2')

# Google App Engine imports.
from google.appengine.ext.webapp import util

# Force Django to reload its settings.
from django.conf import settings
settings._target = None

import django.core.handlers.wsgi
import django.core.signals
import django.db
import django.dispatch

# Log errors.
#import logging
#def log_exception(*args, **kwds):
#    logging.exception('Exception in request:')
#
#django.dispatch.Signal.connect(
#    django.core.signals.got_request_exception, log_exception)

# Unregister the rollback event handler.
django.dispatch.Signal.disconnect(
    django.core.signals.got_request_exception,
    django.db._rollback_on_exception)

def main():
    # Create a Django application for WSGI.
    application = django.core.handlers.wsgi.WSGIHandler()

    # Run the WSGI CGI handler with that application.
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()
于 2013-09-23T17:57:17.417 回答