Django应用程序的GAE配置

2024-03-28 10:05:25 发布

您现在位置:Python中文网/ 问答频道 /正文

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

在主.py在

import webapp2

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

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

在应用程序yaml在

^{pr2}$

Tags: 文件djangopyimportself应用程序defclass
1条回答
网友
1楼 · 发布于 2024-03-28 10:05:25

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

这是我的什么应用程序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在

^{pr2}$

在主.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()

相关问题 更多 >