It is work in the environment where.
First, create a project. Here, it is called gaedjango.
If you use django included in the SDK, it will be as follows. For other environments, please modify accordingly.
$ export PYTHONPATH='/usr/local/google_appengine/lib/django-1.5/'
$ /usr/local/google_appengine/lib/django-1.5/django/bin/django-admin.py startproject gaedjangoapp
A project will be created in the gaedjangoapp directory.
The Google App Engine application is a file called app.yaml You need to configure the application. Python Application Configuration with app.yaml
app.yaml
application: gaedjangoapp
version: 1
runtime: python27
api_version: 1
threadsafe: yes
libraries:
- name: django
version: "1.5"
builtins:
- django_wsgi: on
appengine_config.py When using Django of SDK, set PYTHONPATH.
For Django1.5, also set DJANGO_SETTINGS_MODULE.
appengine_config.py
# -*- coding: utf-8 -*-
import os
import sys
if os.environ.get('SERVER_SOFTWARE','').startswith('Dev'):
sys.path.append('/usr/local/google_appengine/lib/django-1.5/')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gaedjangoapp.settings")
Usually in django apps,
$ python manage.py runserver
Start the development server with This time it's Google App Engine, so
$ dev_appserver.py .
Start with.
In this state, if you access [http: // localhost: 8080](http: // localhost: 8080), It worked! And the screen in the initial state is displayed.
Create an app that displays Hello World.
$ python manage.py startapp hello
Will create an empty app in the hello directory.
Next, make hello / view.py as follows.
hello/view.py
# -*- coding:utf-8 -*-
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world.")
Next, set urls.py.
gaedjangoapp/urls.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
(r'^$', 'gaedjangoapp.hello.views.index'),
)
Finally, add the application to settings.py.
gaedjangoapp.settings.py
INSTALLED_APPS = (
~~~~~
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'hello',
)
In this state, if you access [http: // localhost: 8080](http: // localhost: 8080), Hello, world. It will be displayed.
Recommended Posts