s3kvir pascon


Django begin
November 1, 2010, 15:10
Filed under: Uncategorized | Tags: , ,

From some time I was wondering how to visualize presence of deputies on sessions in lower house of the Polish parliament. I was also fascinated of Zbigniew Braniecki’s work, but because of small activity in project I started thinking about something similar developed on my own. I don’t know well python either django. So from beginning, step by step I’m going to document my journey through it’s world.

Installing django on Windows

I found interesting project having all I need. Instant Django contains Python, django and additional utilities like Notepad++, Mercurial, WinMerge and Sqlite. All bundled in one executable. When ran it unpacks it’s content to selected directory. To start playing with python, just fire start.bat and windows-shell came upon with modified PATH variable containing links to python and django specified folders.

Setting up project

To create django project execute command

django-admin startproject govstats

First argument is command to execute, second is parameter passing to it. In this case we want to startproject named govstats. After project is created we need to change it’s setting in govstats/setting.py file.

First modify section DATABASE to contain information about sqlite3 engine and path to database file. I also changed timezone and language code for Polish and enabled admin and admin-docs sites.

DATABASES = {
 'default': {
 'ENGINE': 'django.db.backends.sqlite3',
 'NAME': 'govstats.db',
 'USER': '',
 'PASSWORD': '',
 'HOST': '',
 'PORT': '',
 }
}
TIME_ZONE = 'Europe/Warsaw'
LANGUAGE_CODE = 'pl-pl'
INSTALLED_APPS = (
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.admin',
 'django.contrib.admindocs',
)

To enable connecting to admin and admin-docs sites we also need to modify govstats/urls.py file:

from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
 # Example:
 # (r'^govstats/', include('govstats.foo.urls')),

 (r'^admin/doc/', include('django.contrib.admindocs.urls')),
 (r'^admin/', include(admin.site.urls)),
)

When we set up those files we can create database file using command, executing in govstats directory:

python.exe manage.py syncdb

Testing project

To check our site we can run django integrated web server executing command below and visit http://localhost:80/admin address.

python.exe manage.py runserver :80

That’s all for now. Stay tuned!

Advertisement

Leave a Comment so far
Leave a comment



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 )

Connecting to %s



Follow

Get every new post delivered to your Inbox.