简体   繁体   English

GAE配置Django应用

[英]GAE Configure for Django App

Can someone please help me transition a django app into the Google App Engine (GAE)? 有人可以帮我将Django应用程序过渡到Google App Engine(GAE)吗? I would like to be abel to take all of the files in my django app and copy them to the GAE app. 我想成为abel在django应用程序中获取所有文件并将其复制到GAE应用程序。 However, I am not sure how the default files for the GAE should be configured. 但是,我不确定应如何配置GAE的默认文件。 How should main.py file look so that runs the django app like it was designed to do: main.py文件的外观应如何,使其像设计的那样运行django应用程序:

main.py main.py

import webapp2

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

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

app.yaml app.yaml

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

libraries:
- name: django
  version: "1.3"

builtins:
- django_wsgi: on

I have a django app running on app engine. 我在应用程序引擎上运行了django应用程序。 I followed this link to get it up and running. 我点击了此链接以启动并运行它。 http://www.allbuttonspressed.com/projects/djangoappengine . http://www.allbuttonspressed.com/projects/djangoappengine There were a lot of little changes in all of the config files compared to regular django. 与常规django相比,所有配置文件都做了很多小的更改。 I now do not use django as i love app engine and hate django. 我现在不使用django,因为我喜欢应用程序引擎并且讨厌django。 Below are some of my file examples. 以下是我的一些文件示例。 Note in your question you have a webapp2 request handler, you wont use anything like that with django. 请注意,在您的问题中,您有一个webapp2请求处理程序,您不会在django中使用类似的东西。 It will be all of the normal view definitions as functions, not classes like app engine. 它将所有普通视图定义作为函数,而不是像App Engine这样的类。 If you decide to try this approach out, let me know how it goes. 如果您决定尝试这种方法,请告诉我它的进展。

This is what my app.yaml after i follow the link above. 这是我点击上面链接后的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

my settings.py 我的settings.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'),

    )

main.py main.py

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

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

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