Sunday, 15 March 2015

Starting with python's Django Framework

Setting Django on Windows

1. Install python 3.4 It will also install pip.

2. In the PATH variable of windows, add - C:\Python34;C:\Python34\Scripts

3. Open command prompt and run command
>pip install django

This will connect to Internet to download and install Django framework. If you encounter HashCode Error or Timout error, retry the same command.

Once installed, you can verify it by going to python prompt & executing
>>import django

Creating the first Django project

1. Open command prompt & go to the directory where you want to create your frist site.

2. Execute command >django-admin.py startproject firstsite

Besides __init__.py, the startproject command creates following other important files.

manage.py -  It is a utility for working with this Django project. We run it in a moment.

settings.py - It is a file containing default settings for your project.E.g. database information, debugging flags etc.

urls.py - This is what’s known in Django as a URLconf, a configuration file that maps URL patterns to actions your applications perform. URLconfs are an exciting and powerful feature of Django.

Starting the server

> python manage.py runserver 8080

An error may occur if the port is bound to some other process. In that case retry with a different port number. Once successful, you can hit the URL from the browser.


Note: This server is not for production environment. It is just for test which automatically detects which python modules are updated during development and reloads them, making the development easy.

If you check the command prompt where you have started the server, you can find the log entry for the request.

This was just about a successful setup. Next we learn how to create some simple sites.

No comments:

Post a Comment

Your comments are very much valuable for us. Thanks for giving your precious time.