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
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
Working from the Packt Pubs Django book.
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.


== Get source ==
== What exactly do I get with Django? ==


Now a github project.
A nice mvc and orm based framework for writing web-based applications.
Download / build / install into /usr/local


cd ~/src
An administration module that includes web-based user account management. If you enable it. http://localhost:8000/admin/
git clone https://github.com/django/django.git
Look at all the code I didn't have to write. Marvelous.
cd django
sudo python setup.py install


test
== Initial tests ==
  django-admin.py
 
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 sample app ====
 
# For simplicity, same place as the project.
cd ~/Projects/gcm_test_site
python manage startapp poll
 
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
poll/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
 
=== GCM ===
 
After downloading django-gcm from github, running make will upgrade your django installation and install requirements.
 
sudo make
 
It misses mimeparse though. Hence
 
sudo pip install mimeparse
 
Pip reminds me of cpan. ''Ah, the golden days of perl! How I fail to miss them!'' Cpan was a high point actually.
 
cd example/
python manage.py syncdb
python manage.py runserver 0.0.0.0:8000
 
...answered a couple q's and we're running. Log in with browser to http://yourhost:8000/admin/

Latest revision as of 23:15, 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.

What exactly do I get with Django?

A nice mvc and orm based framework for writing web-based applications.

An administration module that includes web-based user account management. If you enable it. http://localhost:8000/admin/ Look at all the code I didn't have to write. Marvelous.

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 sample app

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

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 poll/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

GCM

After downloading django-gcm from github, running make will upgrade your django installation and install requirements.

sudo make

It misses mimeparse though. Hence

sudo pip install mimeparse

Pip reminds me of cpan. Ah, the golden days of perl! How I fail to miss them! Cpan was a high point actually.

cd example/
python manage.py syncdb
python manage.py runserver 0.0.0.0:8000

...answered a couple q's and we're running. Log in with browser to http://yourhost:8000/admin/