s3kvir pascon


Running django admin docs
November 2, 2010, 16:00
Filed under: Uncategorized | Tags: , ,

In last post we enabled in application two urls – for admin and admin-docs sites. When testing application by running runserver command we are able to visit admin site. But why admin-doc returns an error?

The problem is that our installation of python doesn’t have docutils package required by admin-doc site. To fix it we need to install this package. Here I describe steps needed to fix admin-doc site.

Installing setuptools

Default Instant Django installation doesn’t contain setuptools package, which we use for installing docutils. If we want to install setuptools on Windows system we can pass into some troubles. But after a while we find a solution:

  1. Download setuptools-XXX.tar.gz
  2. Download setuptools-XXX.egg to a folder(directory) outside your Windows Python installation folder
  3. Use 7-zip to extract ez_setup.py in the same folder as setuptools-XXX.egg
  4. Run start.exe from our Instant Django installation
  5. Go to the folder containing extracted setuptools and run python.exe ez_setup.py setuptools-XXX.egg from the command prompt

Installing docutils

If installation of setuptools package went ok, we are able to install docutils just by running:

easy_install.exe docutils

That’s all for now. Stay tune!



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!




Follow

Get every new post delivered to your Inbox.