Today I tried to setup the Django Framework using the included tutorial. That tutorial is very well written and covers a lot, sometimes a bit too much (if you are a Python, Django rookie like me). So I tried to boil it down to a couple of steps in order to make it easier and faster to install.

There is no info about configuring Apache with mod_python to work with Django here yet. I am assuming you will use the inbuilt development server to test your source, so skip the Apache part in the first step if you like.

1) Install Apache with mod_python module and download Django Web Framework.

2) Install Python.

3) Install Django by placing the Django folder into “Python/Lib/site-packages/” or
use the Django installer. There is a problem when using the installer from a second level directory e.g.

…error: package directory ‘\django’ does not exist

Fix that by changing line 24 in setup.py file from

package = dirpath[len_root_dir:].lstrip(’/').replace(’/', ‘.’)

to

package = dirpath[len_root_dir:].lstrip(’\\’).replace(’\\’, ‘.’)

Read more about it here :

Dont know where Python is installed? Use this command to find the “/site-packages” folder:

python -c

>>>from distutils.sysconfig import get_python_lib

>>>print get_python_lib()

4) Add the Python directory and the “django-admin.py” file to your classpath e.g.

  • Python: set path=%path%;D:\Kosmal\Web\Python
  • django-admin.py: set path=%path%;D:\Kosmal\Web\Python\Lib\site-packages\django\bin

This will make it way more comfortable to use the Python interpreter.

5) Check the Django installation by invoking the Python interpreter using the command line. From a shell type “python” and from prompt type “import django“. If there is no error message, Django was correctly installed.

6) Creating a test project.

Switch to the directory in where you want your test project to be deployed and run the command “django-admin.py startproject mysite“. This creates a folder in the current directory called “mysite“.

Created files in “mysite” folder:

  • __init__.py: An empty file that tells Python that this directory
    should be considered a Python package. (Read `more about packages`_ in the
    official Python docs if you’re a Python beginner.)
  • manage.py: A command-line utility that lets you interact with this
    Django project in various ways.
  • settings.py: Settings/configuration for this Django project.
  • urls.py: The URL declarations for this Django project; a “table ofcontents” of your Django-powered site.

7) Check your project with the build in lightweight server. Switch to the “mysite” directory and run the command “manage.py runserver“. You now should see following output:

  • Validating models…
    0 errors found.
    Django version 0.95, using settings ‘mysite.settings’
    Development server is running at http://127.0.0.1:8000/
    Quit the server with CONTROL-C (Unix) or CTRL-BREAK (Windows).

Now that the server is running, visit http://127.0.0.1:8000/ with your Web
browser.

By default, the “runserver” command starts the development server on port
8000. If you want to change the server’s port, pass it as a command - line
argument. For instance, this command starts the server on port 8080:

python manage.py runserver 8080

8) Database setup (assuming there is already a database installed, I used PostgreSQL ).

Open the file “settings.py” and edit the database settings with database connection details like engine, database name, user, password etc.
Make sure the database exists before going on to the next step.

Django comes with installed default applications which require at last one table in the
database. Scroll down the “settings.py” to see which applications there are.

Run the command “python manage.py syncdb” which will create the essential tables in the database. When running on a windows machine and using PostgreSQL make sure to install the psycopg python-postgresql database interface windows port which you can download here:

If you are getting an errormessage that ends something like this after using the
python manage.py dbsync” command:

…Value Error : invalid literal for int() with base 10: ‘3,’ at line 57 of base.py

you have to replace that line of code with the following line:

postgres_version = [int(val.strip(’,')) for val in cursor.fetchone()[0].split()[1].split(’.')]

Read more about this here:

Now Django is properly setup and can connect to the database. I have installed this on a Windows Vista OS but I am pretty sure this will work in XP/2000 whatever too. Make sure to read the Django documentation as well.

Posted on July 29th, 2008 | Filed under Frameworks | No Comments »

I coded this Mastermind game in Java while working on a project at work. This is the method that checks the players answer to the color question.

What this does is it first compares the color answer with the color question for color and position matches. If a match was found the variable black will be raised by one. This match is taken out for the the next check since a match can only generate a black or a white token. Second check is the color check. If a match was found the variable white will be raised by one.

Another fancy method is the one that generates randomly the color combination for the color question at the beginning of the game.

Those are just two methods of the game probably the more important ones. Those at least did cost me some brain effort. If you like you can download the source files of the Java Mastermind game on my download page.

Posted on July 14th, 2008 | Filed under Java | No Comments »

To change the default icon of your .exe file click on :

  1. Project
  2. [Project Name] Properties
  3. Application
  4. Icon
  5. (From the Combobox select) <Browse…>

and pick your icon. There you go.

Posted on June 7th, 2008 | Filed under C#, Tips | No Comments »

First of all you need a icon. For starters you can use the Favicon Generator. Just generate a random icon. Its not important how it looks, its just important that you get a icon. You always can replace it with something that is more fancy looking later. I placed the icon in the debug and release folders of my project. If you want to place the icon elsewhere just edit the path so that it suits your needs.

Here is the code :

This will send your application to the systemtray when you minimize the window. It wont be shown in the taskbar. If you click on the icon in the systemtray the application will be shown in its original size.

Ow yeah, in case you are trying to put this into a existing project make sure to add this into your Form1.Designer.cs :

This bit of code goes into the InitializeComponent() method.

Posted on June 4th, 2008 | Filed under C# | No Comments »

This weekend I was invited by Johann to big tech day held by TNG Technology Consulting. On friday I had the opportunity to listen to some real interesting talks such as Behaviour Driven Development and Storytests, Search Engine Optimization, held by Johann himself, Farbrausch, the Demoscene and digital art, Animal-inspired Robotics, Making Massive Crowds of Nanotubes and The mystery of the beginning held by Dr.Harald Lesch. It was great fun, for more info check out the bigtechday website.

On saturday Johann organized a mountain hike. Bavaria is so beautyful. I took some pictures while we have been on our way to the top of the Rotwand. Johann recorded the tour with his gps watch. Just check it out in Google Earth once I uploaded it to this server (which will probably happen on monday evening). For now enjoy some of the pictures :

Rotwand_1

Rotwand_2

Rotwand_2

Rotwand_3

Rotwand_4

More pictures incoming soon.

Posted on May 31st, 2008 | Filed under Misc | 2 Comments »