Django on AppEngine Documentation



Similar documents
django-gcm Documentation

Rapid Website Deployment With Django, Heroku & New Relic

Python and Google App Engine

Django Two-Factor Authentication Documentation

Nupic Web Application development

latest Release 0.2.6

DevKey Documentation. Release 0.1. Colm O Connor

Memopol Documentation

django-cron Documentation

AuShadha Documentation

Slides from INF3331 lectures - web programming in Python

Django FTP Deploy Documentation

MyMoney Documentation

Django Web Framework. Zhaojie Zhang CSCI5828 Class Presenta=on 03/20/2012

Effective Django. Build Nathan Yergler

Introduction to web development with Python and Django Documentation

Installing and Running the Google App Engine On Windows

DjNRO Release 0.9 July 14, 2015

SagePay payment gateway package for django-oscar Documentation

Using Python, Django and MySQL in a Database Course

Source Code Management for Continuous Integration and Deployment. Version 1.0 DO NOT DISTRIBUTE

EECS 398 Project 2: Classic Web Vulnerabilities

depl Documentation Release depl contributors

Using Toaster in a Production Environment

Android Setup Phase 2

KonyOne Server Installer - Linux Release Notes

WebIOPi. Installation Walk-through Macros

How to Backup XenServer VM with VirtualIQ

Monitoring Oracle Enterprise Performance Management System Release Deployments from Oracle Enterprise Manager 12c

Magento OpenERP Integration Documentation

Introduction to FreeNAS development

Getting Started with the Ed-Fi ODS and Ed-Fi ODS API

StoreGrid Backup Server With MySQL As Backend Database:

How to deploy fonts using Configuration Manager 2012 R2

How To Backup A Database On A Microsoft Powerpoint 3.5 (Mysqldump) On A Pcode (Mysql) On Your Pcode On A Macbook Or Macbook (Powerpoint) On

Backup and Restore the HPOM for Windows 8.16 Management Server

Central Administration QuickStart Guide

Yocto Project Eclipse plug-in and Developer Tools Hands-on Lab

Using and Contributing Virtual Machines to VM Depot

Setting up VMware Server v1 for 2X VirtualDesktopServer Manual

IceWarp to IceWarp Server Migration

BIRT Application and BIRT Report Deployment Functional Specification

Continuous Delivery on AWS. Version 1.0 DO NOT DISTRIBUTE

CycleServer Grid Engine Support Install Guide. version 1.25

NaviCell Data Visualization Python API

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

Kony MobileFabric. Sync Windows Installation Manual - WebSphere. On-Premises. Release 6.5. Document Relevance and Accuracy

How to Create a Delegated Administrator User Role / To create a Delegated Administrator user role Page 1

Pyak47 - Performance Test Framework. Release 1.2.1

NSi Mobile Installation Guide. Version 6.2

Assignment # 1 (Cloud Computing Security)

Ettema Lab Information Management System Documentation

NGASI Universal APP Panel Administration and User Guide WebAppShowcase DBA NGASI

i5k_doc Documentation

pure::variants Transformer for Software Configuration Management Manual

Smartphone Pentest Framework v0.1. User Guide

Whisler 1 A Graphical User Interface and Database Management System for Documenting Glacial Landmarks

Web Application Frameworks. Robert M. Dondero, Ph.D. Princeton University

SAS Marketing Optimization. Windows Installation Instructions for Hot Fix 51mo14

Copyright 2014, SafeNet, Inc. All rights reserved.

Acronis Backup & Recovery 10 Advanced Server Virtual Edition. Quick Start Guide

KonyOne Server Prerequisites _ MS SQL Server

ALERT installation setup

Creating a Java application using Perfect Developer and the Java Develo...

Administrator s Guide

django-helpdesk Documentation

About This Document 3. About the Migration Process 4. Requirements and Prerequisites 5. Requirements... 5 Prerequisites... 5

MS 10978A Introduction to Azure for Developers

Django FTP server Documentation

Git - Working with Remote Repositories

Using sftp in Informatica PowerCenter

Install guide for Websphere 7.0

1. Product Information

Course Summary. Prerequisites

EMC SourceOne for Microsoft SharePoint Storage Management Version 7.1

MySQL Quick Start Guide

Developing Microsoft Azure Solutions 20532B; 5 Days, Instructor-led

Django Mail Queue Documentation

Exam Name: IBM InfoSphere MDM Server v9.0

Integrity Checking and Monitoring of Files on the CASTOR Disk Servers

SAIP 2012 Performance Engineering

Practice Fusion API Client Installation Guide for Windows

Migrating helpdesk to a new server

Umbraco Courier 2.0. Installation guide. Per Ploug Hansen 5/24/2011

TECHNICAL NOTE SETTING UP A STRM UPDATE SERVER. Configuring your Update Server

Satchmo Documentation

Ipswitch Client Installation Guide

How To Install Storegrid Server On Linux On A Microsoft Ubuntu 7.5 (Amd64) Or Ubuntu (Amd86) (Amd77) (Orchestra) (For Ubuntu) (Permanent) (Powerpoint

pure::variants Connector for Version Control Systems Manual

Central Administration User Guide

Windows Server Update Services 3.0 SP2 Step By Step Guide

Transcription:

Django on AppEngine Documentation Release Sebastian Pawluś October 18, 2014

Contents 1 Installation 3 1.1 Download latest Google AppEngine SDK................................ 3 1.2 Install Django.............................................. 3 1.3 Create Django project.......................................... 3 1.4 Install django-rocket-engine....................................... 3 1.5 Register application on Google AppEngine............................... 3 1.6 Create CloudSQL database........................................ 4 1.7 Configuration............................................... 4 2 Requirements 9 2.1 Google AppEngine SDK libraries:.................................... 9 2.2 Python requirements.txt......................................... 9 3 Blob Storage 11 4 Commands 13 4.1 appengine................................................. 13 4.2 on_appengine............................................... 13 5 Settings 15 5.1 DATABASES............................................... 15 5.2 DEFAULT_FILE_STORAGE...................................... 15 5.3 APPENGINE_PRE_UPDATE...................................... 16 5.4 APPENGINE_POST_UPDATE..................................... 16 i

ii

Welcome to the documentation for django-rocket-engine - Django on AppEngine Project is a helper library with main goal to help setup correct Django development environment for Google AppEngine services. Supports: basic support for pip style requirements, support for virtualenv environments, pre/post deployment hooks, seamless BlobStorage backend. The project is still in the experimental stage, being more like proof-of-concept. Source code can be found on github. This project was inspired by the work of Waldemar Kornewald and Thomas Wanschik from All Buttons Pressed, some ideas where moved from djangoappengine project. Example application Contents 1

2 Contents

CHAPTER 1 Installation 1.1 Download latest Google AppEngine SDK Get the latest version of SDK, if you are using Linux please make sure that SDK is available on your PATH (how?). 1.2 Install Django Install Django framework. There are many ways of doing that (suggestion is to use virtualenv along with virtualenvwrapper and pip) $ pip install django==1.3.1 Note: Version 1.3.1 is latest supported by SDK 1.3 Create Django project Create a new, awesome Django project. Right now it s even more awesome because this project will use AppEngine: $ django-admin.py startproject my_awesome_project 1.4 Install django-rocket-engine Install latest version of django-rocket-engine, with pip $ pip install django-rocket-engine 1.5 Register application on Google AppEngine Register new application on Google AppEngine site. 3

1.6 Create CloudSQL database Create a CloudSQL database instance using Google Api Console, add application instance name from previous step in Authorized applications. Using SQL Prompt tab create a database inside your CloudSQL instance. CREATE DATABASE database_name; 1.7 Configuration Google AppEngine requires applications to have an config in app.yaml file, which is responsible for basic description, and how to manage the application. Create app.yaml inside project directory. Example of app.yaml for project. # app.yaml application: unique_appengine_appspot_id version: 1 runtime: python27 api_version: 1 threadsafe: true handlers: - url: /.* script: rocket_engine.wsgi libraries: - name: django version: 1.3 env_variables: DJANGO_SETTINGS_MODULE: settings Things that need to be done in settings.py are presented in code snippet below: # settings.py from rocket_engine import on_appengine... # django-rocket-engine as every Django application # needs to be added to settings.py file in INSTALLED_APPS section: INSTALLED_APPS = ( # other django applications here #... ) rocket_engine, # remove project name from ROOT_URLCONF. # AppEngine doesn t treat project as a module # like normal Django application does. ROOT_URLCONF = urls # to use different databases during # development process and on production. if on_appengine: DATABASES = { 4 Chapter 1. Installation

default : { ENGINE : rocket_engine.db.backends.cloudsql, INSTANCE : instance:name, NAME : database_name, else: DATABASES = { default : { ENGINE : django.db.backends.sqlite3, NAME : development.db # disable debugging on production DEBUG = not on_appengine Note: Instead of using sqlite3 backend your are able to use MySQL backend. This should also be your choice for serious applications. That s just about it. Application is ready to run: $ python manage.py syncdb $ python manage.py runserver and deploy: $ python manage.py on_appengine syncdb $ python manage.py appengine update --oauth2 Have fun! 1.7.1 Next Steps Requirements Google AppEngine SDK libraries: Google AppEngine SDK comes with sets of libraries. If there is a need to use one of them, you should append the library in your libraries seduction in app.yaml file rather to add them with use of requirements.txt file (explained below). Example of how to enable lxml in application. # app.yaml #... libraries: - name: django version: 1.3 - name: lxml version: 2.3 1.7. Configuration 5

Python requirements.txt To bring AppEngine development to more pythonic status. The library comes with basic support for python packaging system, You can keep list of required packages in requirements.txt file in your project root directory. Example of requirements.txt for simple project may contains packages like: django-tastypie django-taggit>=0.4 These packages will be downloaded and installed during deployment stage (manage.py appengine update). Requirements file may also contain references to packages being under source control: git+git://github.com/alex/django-taggit.git git+git://github.com/jezdez/django-dbtemplates.git@master Note: There is no need to add django or django-rocket-engine to your requirements.txt file. Those requirements are already satisfied. Note: Editable requirements (prepended with -e option) are not supported. More about using requirements file might be read here. Commands appengine Google AppEngine comes with appcfg.py to cover all functionality of the deployment process. This command is currently now wrapped by appengine django command and comes with some benefits of configuration hooks: python manage.py appengine update Calling this command will send your code on remote AppEngine instance. This option comes with support of pre and post update hooks see Settings. on_appengine To perform an operation on Google AppEngine from your local machine use: python manage.py on_appengine syncdb This command will perform a sycndb operation on your remote instance. Google AppEngine doesn t come with any kind of remote access mechanism (like SSH, Talent), this command helps to overcome this inconvenience. Any command invoked this way will be called to use of remote storage instead of your local one. This command only affects storage. Other useful examples might be. remote python shell: python manage.py on_appengine shell remote CloudSQL shell: python manage.py on_appengine dbshell migrate database if South is being used: 6 Chapter 1. Installation

python manage.py on_appengine migrate Blob Storage To enable BlobStorage system as a Django storage, modify your code with elements presented below. # urls.py urlpatterns = patterns(... url(r ^media/(?p<filename>.*)/$, rocket_engine.views.file_serve ), ) # settings.py DEFAULT_FILE_STORAGE = rocket_engine.storage.blobstorage Settings DATABASES django-rocket-engine comes with pre-defined backend Google CloudSQL wrapper which prevents using your production database during development: DATABASES = { default : { ENGINE : rocket_engine.db.backends.cloudsql, INSTANCE : instance:name, NAME : database_name, To distinguish between production and development. The library provides helper method which could applied in settings.py: # settings.py from rocket_engine import on_appengine... if on_appengine: DATABASES = { default : { ENGINE : rocket_engine.db.backends.cloudsql, INSTANCE : instance:name, NAME : database_name, else: DATABASES = { default : { ENGINE : django.db.backends.sqlite3, NAME : development.db 1.7. Configuration 7

DEFAULT_FILE_STORAGE Use this setting to setup Blob objects as a default project storage. DEFAULT_FILE_STORAGE = rocket_engine.storage.blobstorage APPENGINE_PRE_UPDATE Callable that will be applied before sending application to Google AppEngine. Default: APPENGINE_PRE_UPDATE = appengine_hooks.pre_update APPENGINE_POST_UPDATE Callable that will be applied after sending application to Google AppEngine. Default: APPENGINE_POST_UPDATE = appengine_hooks.post_update Example of appengine_hooks.py file: from django.core.management import call_command def pre_update(): call_command( collectstatic ) def post_update(): call_command( on_appengine, syncdb ) # If south is being used call_command( on_appengine, migrate ) 8 Chapter 1. Installation

CHAPTER 2 Requirements 2.1 Google AppEngine SDK libraries: Google AppEngine SDK comes with sets of libraries. If there is a need to use one of them, you should append the library in your libraries seduction in app.yaml file rather to add them with use of requirements.txt file (explained below). Example of how to enable lxml in application. # app.yaml #... libraries: - name: django version: 1.3 - name: lxml version: 2.3 2.2 Python requirements.txt To bring AppEngine development to more pythonic status. The library comes with basic support for python packaging system, You can keep list of required packages in requirements.txt file in your project root directory. Example of requirements.txt for simple project may contains packages like: django-tastypie django-taggit>=0.4 These packages will be downloaded and installed during deployment stage (manage.py appengine update). Requirements file may also contain references to packages being under source control: git+git://github.com/alex/django-taggit.git git+git://github.com/jezdez/django-dbtemplates.git@master Note: There is no need to add django or django-rocket-engine to your requirements.txt file. Those requirements are already satisfied. Note: Editable requirements (prepended with -e option) are not supported. More about using requirements file might be read here. 9

10 Chapter 2. Requirements

CHAPTER 3 Blob Storage To enable BlobStorage system as a Django storage, modify your code with elements presented below. # urls.py urlpatterns = patterns(... url(r ^media/(?p<filename>.*)/$, rocket_engine.views.file_serve ), ) # settings.py DEFAULT_FILE_STORAGE = rocket_engine.storage.blobstorage 11

12 Chapter 3. Blob Storage

CHAPTER 4 Commands 4.1 appengine Google AppEngine comes with appcfg.py to cover all functionality of the deployment process. This command is currently now wrapped by appengine django command and comes with some benefits of configuration hooks: python manage.py appengine update Calling this command will send your code on remote AppEngine instance. This option comes with support of pre and post update hooks see Settings. 4.2 on_appengine To perform an operation on Google AppEngine from your local machine use: python manage.py on_appengine syncdb This command will perform a sycndb operation on your remote instance. Google AppEngine doesn t come with any kind of remote access mechanism (like SSH, Talent), this command helps to overcome this inconvenience. Any command invoked this way will be called to use of remote storage instead of your local one. This command only affects storage. Other useful examples might be. remote python shell: python manage.py on_appengine shell remote CloudSQL shell: python manage.py on_appengine dbshell migrate database if South is being used: python manage.py on_appengine migrate 13

14 Chapter 4. Commands

CHAPTER 5 Settings 5.1 DATABASES django-rocket-engine comes with pre-defined backend Google CloudSQL wrapper which prevents using your production database during development: DATABASES = { default : { ENGINE : rocket_engine.db.backends.cloudsql, INSTANCE : instance:name, NAME : database_name, To distinguish between production and development. The library provides helper method which could applied in settings.py: # settings.py from rocket_engine import on_appengine... if on_appengine: DATABASES = { default : { ENGINE : rocket_engine.db.backends.cloudsql, INSTANCE : instance:name, NAME : database_name, else: DATABASES = { default : { ENGINE : django.db.backends.sqlite3, NAME : development.db 5.2 DEFAULT_FILE_STORAGE Use this setting to setup Blob objects as a default project storage. 15

DEFAULT_FILE_STORAGE = rocket_engine.storage.blobstorage 5.3 APPENGINE_PRE_UPDATE Callable that will be applied before sending application to Google AppEngine. Default: APPENGINE_PRE_UPDATE = appengine_hooks.pre_update 5.4 APPENGINE_POST_UPDATE Callable that will be applied after sending application to Google AppEngine. Default: APPENGINE_POST_UPDATE = appengine_hooks.post_update Example of appengine_hooks.py file: from django.core.management import call_command def pre_update(): call_command( collectstatic ) def post_update(): call_command( on_appengine, syncdb ) # If south is being used call_command( on_appengine, migrate ) 16 Chapter 5. Settings