How to host a django project in google appspot

Do you have a project developed in Django and want to host it somewhere.? You are in right place!.  Google app engine support hosting Django projects. But you have to make some changes in your project including your Django’s ORM.

The prerequisite to do this conversion:
* installed Google Appengine SDK.
* installed django.

Google App Engine supports running any WSGI compliant application. Since Django supports this standard it is possible to build (or port existing) Django applications to run on Google App Engine.

your django project may contain the following files:
__init__.py     —   tells Python this is a package
urls.py               —   global URL config (“URLconf”) file
settings.py       —   project-specific configuration
manage.py       — command-line interface for apps

‘your app directory’ contains the following files:
__init__.py    — same as above
models.py        — data models
views.py           — request handlers
tests.py             — unit tests (optional but strongly-encouraged)

Inorder to convert your project to GAE do the following steps:

1) Create a directory for the appengine version of your project. Lets call it ‘my_gae_project’.

2) Inside the directory create a ‘app.yaml‘ file which may look like this.
3) copy this main.py and settings.py files to your application folder. You dont need to change the content of these files.
4) copy views.py and urls.py files from your django project to ‘my_gae_project’.

5) inside urls.py ,if there is ‘admin.autodiscover()’, remove that line.
ensure that you have given correct path for url mapping.

6) Google App Engine does not provide an SQL database so you cannot use Django’s standard Model class. So you have to convert your database models that suit to App Engine models (from google.appengine.ext import db). get help from : http://code.google.com/p/google-app-engine-django

This is not a big deal. you can do this with little effort, and put these new database models inside view.py.

also change the queries used inside the views.py file to GQL.

7)Google App Engine restricts certain module imports and actions that Django tries to perform (such as creating and removing the test database). Appengine have a helper that prevents you from needing to worry about most of these differences.

ex: ‘ from django.shortcuts import get_object_or_404’. we have to remove all such import from our views.py.

8 ) create a ‘template’ directory inside current directory and place all your template files( html files) inside a template directory .

9) create a ‘static’ directory and place all your static files inside that directory.

now your directory structure look like this:

my_gae_project
-‘static'(directory)
-‘templates'(directory)
-app.yaml
-main.py
-settings.py
-urls.py
-views.py

now you can deploy your django site to appengine as you are deploying your appengine project.

(The above methode worked for my url shortening project. Here is the link . Hope this will work for you too. Best wishes…)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s