Showing posts with label django. Show all posts
Showing posts with label django. Show all posts

Friday, February 25, 2011

Django Basic Note

To create an application within a project, run the following command:

$ python manage.py startapp <app-name>

After writing a data model, the following command should be run to create the corresponding tables in the database:

$ python manage.py syncdb

To view the SQL queries generated by Django, issue the following command:

$ python manage.py sql <app-name>

Data models provide a variety of methods to interact with the database engine:

The objects.get method retrieves an object by a unique field
The objects.all method retrieves a list of all objects
The save method saves an object into the database
The delete method deletes an object from the database

To generate a Page not found (404) error, raise an exception of type Http404.




Thursday, February 17, 2011

Small Note On DJango

Django can be downloaded from the official Django website at
http://www.djangoproject.com/. Given that it is written in Python,
the same package works on all major operating systems.

To start a new Django project, issue the following command:
$ django-admin.py startproject <project-name>

To edit database information, edit settings.py of <project-name> folder.

To create database tables, issue the following command:
$ python manage.py syncdb


To start the development server, issue the following command:
$ python manage.py runserver


Django project settings are stored in the settings.py file. This file is a
regular Python source file that can be edited using any source code editor.
To change a variable, simply assign the desired value to it.

Wednesday, February 16, 2011

Installing Django on UNIX/Linux and Mac OS X

Installation instructions for all UNIX and Linux systems are the same. You need to run the following commands in the directory where the Django-x.xx.tar.gz archive is located. These commands will extract the archive and install Django for you:

$ tar xfz Django-x.xx.tar.gz
$ cd Django-x.xx
$ sudo python setup.py install

or in Debian Distributions,

$ sudo apt-get install python-django

You can test your installation by running this command:

$ django-admin.py --version