Sunday, November 18

Getting Started with Django - Installing on Windows.

Initially I had started learning python with python 3.x. And the next step was to work on a web application. Django being the most popular, I jumped into installing it.

Note : Django does not work with python 3.x. It only supports python 2.x
You can read about it in their FAQ's here (https://docs.djangoproject.com/en/dev/faq/install/#can-i-use-django-with-python-3)

I tried running Django 1.4 on python 3 but since it does not support python 3, will not discuss the issues i faced. I then uninstalled python3 and then installed pyhon2.7.3

After installing python2.7.3, I updated my Environment Variables.
I then got the Django folder extracted and stored it in C: drive. Through the command prompt, I followed below steps to install Django.

C:/>cd Django-1.4.2
C:/Django-1.4.2>python setup.py install

The above command installed Django on my python directory in Lib/Site-Packages folder. Also it created a django-admin.py in the python scripts folder.

After installing I checked if django was installed correctly? For that get into the python interpreter in command prompt, i.e type python in your command prompt and then type import django. If no error, then django is installed correctly.

I then created a path variable for python scripts folder, so that the django-admin.py script could be run from anywhere. Also created a path for django/bin folder in the environment variable. When i tried to create a django project it showed a help menu. Any django-admin.py command would return a help menu of django, which is not an expected output.

See below screenshot.


After a lot of googling and stackoverflow, the django path to create a project did not work and hence, i had to settle with using the absolute path to my django script as below.

F:/> cd projects/python
F:/projects/python>F:/python27/Scripts/django-admin.py setupproject mysite

The above script executes and it creates the required mysite project in the directory.

However, i was looking for a possible solution so that i don't have to use the absolute path to the django folder to create my django projects. It appears that in windows, the issue could be with the way registry is stored. A little bit of stackoverflow got me to this helpful link.
http://stackoverflow.com/questions/9107196/django-admin-py-prints-help-only

I then immediately checked my registry entries using the windows regedit.exe command. Checked both python.exe unders applications folder and .py entry for the correct path. python.exe had the correct entry which is

"F:\Python27\python.exe" "%1" %*

However the .py folder in regedit did not show correct value. It showed

"F:\Python27\python.exe" "%1" //Wrong!

Which is wrong. I updated the .py entry using the FileTypesManager software and then tried again to see if the django-admin command worked.

F:\Projects\Python>django-admin.py --version
1.4.2

Be the first one to Comment!!!

Post a Comment