Programing

Google App Engine의 프로젝트 구조

lottogame 2020. 7. 16. 08:09
반응형

Google App Engine의 프로젝트 구조


나는 오랫동안 생각해 왔지만 결코 시작하지 않은 애완 동물 프로젝트에서 기술을 사용하고 작업하기 위해 Google App Engine에서 응용 프로그램을 시작했습니다. 결과는 BowlSK 입니다. 그러나 성장하고 기능이 추가됨에 따라 일을 정리하는 것이 실제로 어려워졌습니다. 주로 이것이 첫 번째 파이썬 프로젝트라는 사실 때문에 일을 시작하기 전까지는 아무것도 몰랐습니다.

내가 가진 것 :

  • 메인 레벨은 다음을 포함합니다 :
    • 모든 .py 파일 (패키지 작동 방법을 몰랐 음)
    • 기본 레벨 페이지의 모든 .html 템플리트
  • 하위 디렉토리 :
    • CSS, 이미지, js 등을위한 별도의 폴더
    • 서브 디렉토리 유형 URL 용 .html 템플리트가있는 폴더

예 :
http://www.bowlsk.com/ 은 홈페이지 (기본 패키지)에 매핑 되고 "index.html"의 템플릿에
http://www.bowlsk.com/games/view-series.html?series=7130에 매핑됩니다 ViewSeriesPage (기본 패키지), "games / view-series.html"의 템플릿

불쾌합니다. 재구성은 어떻게합니까? 나는 2 가지 아이디어가 있었다.

  • 주 폴더 : appdef, indexes, main.py?

    • 코드의 하위 폴더 이것이 첫 번째 패키지 여야합니까?
    • 템플릿의 하위 폴더. 폴더 계층 구조는 패키지 계층 구조와 일치합니다.
    • CSS, 이미지, js 등을위한 개별 하위 폴더
  • appdef, 인덱스, main.py를 포함하는 메인 폴더?

    • 코드 + 템플릿 용 하위 폴더 이렇게하면 템플릿 바로 옆에 처리기 클래스가 있습니다.이 단계에서는 많은 기능을 추가하기 때문에 하나의 수정은 다른 수정을 의미합니다. 다시,이 폴더 이름이 클래스의 첫 번째 패키지 이름이어야합니까? 폴더를 "src"로하고 싶지만 클래스가 "src.WhateverPage"가되기를 원하지 않습니다.

모범 사례가 있습니까? Django 1.0과 함께 공식 GAE 템플릿 엔진이 될 때 통합 기능을 향상시키기 위해 지금 할 수있는 일이 있습니까? 나는 단순히 이런 것들을 시도해보고 어느 것이 더 좋아 보이는지 알지만, pyDev의 리팩토링 지원은 패키지 이동을 잘 처리하지 못하는 것 같으 므로이 모든 작업을 다시 수행하는 것은 사소한 작업이 아닐 것입니다.


첫째, 난 당신이 "한 번 봐 가지고 제안 파이썬, 장고, 구글 앱 엔진과 신속한 개발을 "

GvR은 슬라이드 프레젠테이션 10 페이지의 일반 / 표준 프로젝트 레이아웃을 설명합니다 .

여기에서는 해당 페이지에서 약간 수정 된 레이아웃 / 구조 버전을 게시합니다. 나는이 패턴을 거의 따랐다. 또한 패키지에 문제가 있다고 언급했습니다. 각 하위 폴더에 __init__.py 파일이 있는지 확인하십시오. 비어 있으면 괜찮습니다.

보일러 플레이트 파일

  • 이들은 프로젝트마다 거의 차이가 없습니다.
  • app.yaml : 모든 비 정적 요청을 main.py로 전달
  • main.py : 앱을 초기화하고 모든 요청을 보냅니다.

프로젝트 레이아웃

  • 정적 / * : 정적 파일; App Engine에서 직접 제공
  • myapp / *. py : 앱별 파이썬 코드
    • views.py, models.py, tests.py, __init__.py 등
  • templates / *. html : 템플릿 (또는 myapp / templates / *. html)

도움이 될만한 코드 예제는 다음과 같습니다.

main.py

import wsgiref.handlers

from google.appengine.ext import webapp
from myapp.views import *

application = webapp.WSGIApplication([
  ('/', IndexHandler),
  ('/foo', FooHandler)
], debug=True)

def main():
  wsgiref.handlers.CGIHandler().run(application)

myapp / views.py

import os
import datetime
import logging
import time

from google.appengine.api import urlfetch
from google.appengine.ext.webapp import template
from google.appengine.api import users
from google.appengine.ext import webapp
from models import *

class IndexHandler(webapp.RequestHandler):
  def get(self):
    date = "foo"
    # Do some processing        
    template_values = {'data': data }
    path = os.path.join(os.path.dirname(__file__) + '/../templates/', 'main.html')
    self.response.out.write(template.render(path, template_values))

class FooHandler(webapp.RequestHandler):
  def get(self):
    #logging.debug("start of handler")

myapp / models.py

from google.appengine.ext import db

class SampleModel(db.Model):

이 레이아웃은 새롭고 비교적 중소 규모의 프로젝트에 적합하다고 생각합니다. 더 큰 프로젝트의 경우 뷰와 모델을 분해하여 다음과 같은 자체 하위 폴더를 갖도록 제안합니다.

프로젝트 레이아웃

  • 정적 / : 정적 파일; App Engine에서 직접 제공
    • js / *. js
    • images / *. gif | png | jpg
    • CSS / *. css
  • myapp / : 앱 구조
    • 모델 /*.py
    • views / *. py
    • 테스트 /*.py
    • templates / *. html : 템플릿

내 평소 레이아웃은 다음과 같습니다.

  • app.yaml
  • index.yaml
  • request.py-기본 WSGI 앱 포함
  • lib
    • __init__.py -요청 핸들러 기본 클래스를 포함한 공통 기능
  • controllers-모든 핸들러를 포함합니다. request.yaml이이를 가져옵니다.
  • 템플릿
    • 컨트롤러가 사용하는 모든 장고 템플릿
  • 모델
    • all the datastore model classes
  • static
    • static files (css, images, etc). Mapped to /static by app.yaml

I can provide examples of what my app.yaml, request.py, lib/init.py, and sample controllers look like, if this isn't clear.


I implemented a google app engine boilerplate today and checked it on github. This is along the lines described by Nick Johnson above (who used to work for Google).

Follow this link gae-boilerplate


I think the first option is considered the best practice. And make the code folder your first package. The Rietveld project developed by Guido van Rossum is a very good model to learn from. Have a look at it: http://code.google.com/p/rietveld

With regard to Django 1.0, I suggest you start using the Django trunk code instead of the GAE built in django port. Again, have a look at how it's done in Rietveld.


I like webpy so I've adopted it as templating framework on Google App Engine.
My package folders are typically organized like this:

app.yaml
application.py
index.yaml
/app
   /config
   /controllers
   /db
   /lib
   /models
   /static
        /docs
        /images
        /javascripts
        /stylesheets
   test/
   utility/
   views/

Here is an example.


I am not entirely up to date on the latest best practices, et cetera when it comes to code layout, but when I did my first GAE application, I used something along your second option, where the code and templates are next to eachother.

There was two reasons for this - one, it kept the code and template nearby, and secondly, I had the directory structure layout mimic that of the website - making it (for me) a bit easier too remember where everything was.

참고URL : https://stackoverflow.com/questions/48458/project-structure-for-google-app-engine

반응형