Django: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
mNo edit summary
Brian Wilson (talk | contribs)
mNo edit summary
Line 58: Line 58:
The gcm_form will have a page with an area for client status and a button to send a dispatch message.
The gcm_form will have a page with an area for client status and a button to send a dispatch message.


Define the database here
gcm_server/models.py
gcm_server/models.py
Create the database by telling django to use sqlite3 and the name of the db file in the settings.py file
then run this to create all the table
python manage.py syncdb

Revision as of 21:10, 3 September 2013

Starting working from a Packt Publishing copy of the Django book, then realized the book itself is an open source project here: http://djangobook.com/ I installed django as described in chaper 2 from the github repo.

Initial tests

My initial testing will be with SQLite, then I will move on to postgresql to get PostGIS going. SQLite is built in to Python so it's a pretty obvious track to follow.

I am also interested to see how to work with Django and Komodo 8.

Installing

I had an old copy installed (1.3.1) and wanted 1.5.2 before pitching headlong into the tutorial.

% sudo pip install django --upgrade
.
.
.
Successfully installed django
% python -c "import django; print(django.get_version())"
1.5.2

Minimal tester

Just want a page to come up so that I can install the Google Cloud Messaging for django thing and try it out. Will set up Django then go look at that page.

Crib sheet

I am working my way through the "getting started" tutorial and making my own notes here.

Set up a django "project"

cd ~/Projects
mkdir Django
cd Django
django-admin.py startproject gcm_test_site

Run it; connect from browser

cd gcm_test_site
python manage.py runserver 0.0.0.0:8000

Connect to the server using its name and port 8000, for example http://wildsong.biz:8000 (example only, nothing there!) You should see:

"It worked!
Congratulations on your first Django-powered page."

Now I need to get it to do something useful. For starters how about emulating the ugly GCM server page, which just has number of registered clients and a send button.

Create a GCM app

# For simplicity, same place as the project.
cd ~/Projects/gcm_test_site 
python manage startapp gcm_server

The gcm_form will have a page with an area for client status and a button to send a dispatch message.

Define the database here gcm_server/models.py

Create the database by telling django to use sqlite3 and the name of the db file in the settings.py file then run this to create all the table

python manage.py syncdb