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.




No comments:

Post a Comment