Module 1
Starting a Project
Starting a Project
A project is a collection of settings for an instance of Django, including database
configuration, Django-specific options, and application-specific settings.
If this is your first time using Django, you’ll have to take care of some initial setup.
Create a new directory to start working in, perhaps something like
/home/username/djcode/, and change into that directory.
Run the command [Link] startproject mysite to create a mysite directory
in your current directory.
Starting a Project
Let’s look at what startproject created:
mysite/
__init__.py
[Link]
[Link]
[Link]
These files are as follows:
• __init__.py: A file required for Python; treat the directory as a package (i.e., a group
of modules)
• [Link]: A command-line utility that lets you interact with this Django project in
various ways
• [Link]: Settings/configuration for this Django project
• [Link]: The URL declarations for this Django project; a “table of contents” of your
Django-powered site
The Development Server
Django includes a built-in, lightweight Web server you can use while developing your
site.
We’ve included this server so you can develop your site rapidly, without having to deal
with configuring your production Web server (e.g., Apache) until you’re ready for
production.
This development server watches your code for changes and automatically reloads,
helping you make many rapid changes to your project without needing to restart
anything.
The Development Server
Change into the mysite directory, if you haven’t done so already, and run the command
python [Link] runserver.
You’ll see something like this:
Validating models...
0 errors found.
Django version 0.96, using settings '[Link]'
Development server is running at [Link]
Quit the server with CONTROL-C.
Creating app
python [Link] startapp myapp
myapp/
__init__.py
[Link]
[Link]
migrations/
__init__.py
[Link]
[Link]
[Link]
Screenshots
Screenshots
Screenshots
Screenshots
Screenshots
12
13
14