![](https://csdnimg.cn/release/download_crawler_static/4282948/bg12.jpg)
Django Documentation, Release 1.3.1
• HOST – The host your database is on. Leave this as an empty string if your database server is on the same
physical machine (not used for SQLite).
If you’re new to databases, we recommend simply using SQLite (by setting ENGINE to
’django.db.backends.sqlite3’). SQLite is included as part of Python 2.5 and later, so you won’t
need to install anything else.
Note: If you’re using PostgreSQL or MySQL, make sure you’ve created a database by this point. Do that with
“CREATE DATABASE database_name;” within your database’s interactive prompt.
If you’re using SQLite, you don’t need to create anything beforehand - the database file will be created automatically
when it is needed.
While you’re editing settings.py, take note of the INSTALLED_APPS setting towards the bottom of the file.
That variable holds the names of all Django applications that are activated in this Django instance. Apps can be used
in multiple projects, and you can package and distribute them for use by others in their projects.
By default, INSTALLED_APPS contains the following apps, all of which come with Django:
• django.contrib.auth – An authentication system.
• django.contrib.contenttypes – A framework for content types.
• django.contrib.sessions – A session framework.
• django.contrib.sites – A framework for managing multiple sites with one Django installation.
• django.contrib.messages – A messaging framework.
• django.contrib.staticfiles – A framework for managing static files.
These applications are included by default as a convenience for the common case.
Each of these applications makes use of at least one database table, though, so we need to create the tables in the
database before we can use them. To do that, run the following command:
python manage.py syncdb
The syncdb command looks at the INSTALLED_APPS setting and creates any necessary database tables according
to the database settings in your settings.py file. You’ll see a message for each database table it creates, and you’ll
get a prompt asking you if you’d like to create a superuser account for the authentication system. Go ahead and do
that.
If you’re interested, run the command-line client for your database and type \dt (PostgreSQL), SHOW TABLES;
(MySQL), or .schema (SQLite) to display the tables Django created.
For the minimalists
Like we said above, the default applications are included for the common case, but not everybody needs them. If you
don’t need any or all of them, feel free to comment-out or delete the appropriate line(s) from INSTALLED_APPS
before running syncdb. The syncdb command will only create tables for apps in INSTALLED_APPS.
2.3.2 Creating models
Now that your environment – a “project” – is set up, you’re set to start doing work.
Each application you write in Django consists of a Python package, somewhere on your Python path, that follows a
certain convention. Django comes with a utility that automatically generates the basic directory structure of an app, so
you can focus on writing code rather than creating directories.
14 Chapter 2. Getting started