>Getting Started: Python > Hello, World!

 

Hello, World!

Python App Engine applications communicate with the web server using the CGI standard. When the server receives a request for your application, it runs the application with the request data in environment variables and on the standard input stream (for POST data). To respond, the application writes the response to the standard output stream, including HTTP headers and content.

파이썬 엡엔진 어플은 CGI 표준을 사용하여 웹서버와 통신을 한다. 서버가 어플의 요청을 받을 때, 지정된 값의 요청 데이터와 데이터 표준 입력 스트림(POST data)으로 어플을 실행한다. 응답시, 어플은 HTTP 헤더와 내용을 포함시켜 표준 외부 스트림으로 응답을 보낸다.

 

Let's begin by implementing a tiny application that displays a short message.

간단한 메세지를 보여주는 작은 어플을 시작해 보자

 

Creating a Simple Request Handler 간단한 요청 핸들 만들기

Create a directory named helloworld. All files for this application reside in this directory.

Inside the helloworld directory, create a file named helloworld.py, and give it the following contents:

helloworld 디렉토리를 만든다. 이 어플의 모든파일은 이 디렉토리에 존재한다. helloworld 디렉토리 안에 helloworld.py 파일을 만들고, 아래 내용을 넣는다.

 

print 'Content-Type: text/plain'

print ''

print 'Hello, world!'

 

This Python script responds to a request with an HTTP header that describes the content, a blank line, and the message Hello, world!

이 파이썬 스크립트는 공백과 Hello, world! 를 보여주는 HTTP 헤더를  응답한다.

 

Creating the Configuration File 환경파일 만들기

An App Engine application has a configuration file called app.yaml Among other things, this file describes which handler scripts should be used for which URLs.

Inside the helloworld directory, create a file named app.yaml with the following contents:

응용 프로그램이 어느 파일을 사용해야 하는지 app.yaml 파일에 구성되어 있다. 그중에 이 파일은 URL을 사용에 따른 핸들러 스크립트를 포함하고 있다. (ㅡㅡ;)

helloworld 디렉토리 안에 app.yaml 파일을 만들고 아래 내용을 넣는다:

 

application: helloworld

version: 1

runtime: python

api_version: 1

handlers:- url: /.*

script: helloworld.py

 

From top to bottom, this configuration file says the following about this application:

처음 부터 끝까지, 이 구성 파일은 이 어플에 대해 아래에 이야기하고 있다.

 

  • The application identifier is helloworld. When you register your application with App Engine in the final step, you will select a unique identifier, and update this value. This value can be anything during development. For now, leave it set tohelloworld.
    어플 식별자는 helloworld. 마지막 단계에 엡엔진에 당신의 어플을 등록할 때, 유니크한 식별자로 업데이트 해야 한다. 이 값은 개발 중이기 때문에 지금은 helloworld로 설정해 놓았다.
  • This is version number 1 of this application's code. If you adjust this before uploading new versions of your application software, App Engine will retain previous versions, and let you roll back to a previous version using the administrative console.
    이 버젼의 어플 코드 번호는 1이다. 만약 전에 업로드한 당신의 어플의 새 버전을 조절하려고 하면, 앱엔진은 이전 버젼을 계속 유지할것이고, 관리 콘솔을 이용하면 이전 버전으로 돌릴 수 있다. (관리 콘솔은 http://appengine.google.com에 접속)

 

  • This code runs in the python runtime environment, version "1". Additional runtime environments and languages may be supported in the future.
    이 코드는 버젼 '1' 파이썬 런타임 환경에서 실행한다. 추가 런타임 환경과 언어는 차후 추가될 예정이다.
  • Every request to a URL whose path matches the regular expression /.* (all URLs) should be handled by the helloworld.py script.
    정규 표현 /.* (모든 URL)의 경로에 대한 모든 요청과 일치하는 URL은 helloworld.py 스크립트를 거쳐야 함을 명시.

 

The syntax of this file is YAML. For a complete list of configuration options, see the app.yaml reference.
이 파일의 문법은 YAML이다. 구헝옵션의 전체 목록을 보려면 the app.yaml reference을 보라

 

Testing the Application 어플 테스트 하기

With a handler script and configuration file mapping every URL to the handler, the application is complete. You can now test it with the web server included with the App Engine SDK.

Start the web server with the following command, giving it the path to the helloworld directory:

핸들러 스크립트와 설정파일은 핸들러로 모든 URL이 맵핑되고, 어플이 완성된다. 지금 앱엔진 SDK에 포함된 웹서버로 테스트 할수 있다.  주어진 helloworld 디렉토리의 경로를 아래의 명령어로 웹서버를 시작하자

 

google_appengine/dev_appserver.py helloworld/

 

The web server is now running, listening for requests on port 8080. Test the application by visiting the following URL in your web browser:

웹서버가 시작 되면, 포트8080 으로 요청을 대기중이다. 웹브라우저에서 아래 URL로 방문해서 어플을 테스트 하자.

 

 

For more information about running the development web server, including how to change which port it uses, see the Dev Web Server reference, or run the command with the option --help.

포트를 바꾸는 등의 개발 웹서버의 실행에 대한 더 많은 정보는, the Dev Web Server reference 를 참조 하거나, -help 옵션과 함께 명령어를 실행 해 보라.

 

Iterative Development 반복 개발

You can leave the web server running while you develop your application. The web server knows to watch for changes in your source files and reload them if necessary.

웹서버가 개발중인 동안에도 어플을  실행할수 있다. 웹 서버의 소스파일의 바뀐 내용을 보려면 새로고침 해야 한다.

 

Try it now: Leave the web server running, then edit helloworld.py to change Hello, world! to something else. Reload http://localhost:8080/ to see the change.

시도해 보자 : 서버를 실행 상태로 , helloworld.py 의 내용을 Hello, world! 처럼 바꿔 보자. http://localhost:8080 으로 새로고침 하면 바뀐걸 볼 수 있다.

 

To shut down the web server, make sure the terminal window is active, then press Control-C (or the appropriate "break" key for your console).

웹서버를 종료하려면, 터미널에서 Ctrl + C 를 입력 (또는 콘솔의 break 키를 입력)

 

You can leave the web server running for the rest of this tutorial. If you need to stop it, you can restart it again by running the command above.

 

Next...

You now have a complete App Engine application! You could deploy this simple greeting right now and share it with users worldwide. But before we deploy it, let's consider using a web application framework to make it easier to add features.

Continue to Using the webapp Framework.

앱엔진을 어플을 만들어 보았다. 간단한 배포로 웹세상에 공유할수 있다. 배포전에, 원하는 기능을 쉽게 추가 할수 있는 프레임 워크를 사용해 보자. 프레임워크 사용하기로..

.

+ Recent posts