Django Getting started with Django Starting a Project


Django is a web development framework based on Python. Django 1.11 (the latest stable release) requires Python 2.7, 3.4, 3.5 or 3.6 to be installed. Assuming pip is available, installation is as simple as running the following command. Keep in mind, omitting the version as shown below will install the latest version of django:

$ pip install django

For installing specific version of django, let's suppose the version is django 1.10.5 , run the following command:

$ pip install django==1.10.5

Web applications built using Django must reside within a Django project. You can use the django-admin command to start a new project in the current directory:

$ django-admin startproject myproject

where myproject is a name that uniquely identifies the project and can consist of numbers, letters, and underscores.

This will create the following project structure:


To run the application, start the development server

$ cd myproject
$ python runserver

Now that the server’s running, visit with your web browser. You’ll see the following page:

enter image description here

By default, the runserver command starts the development server on the internal IP at port 8000. This server will automatically restart as you make changes to your code. But in case you add new files, you’ll have to manually restart the server.

If you want to change the server’s port, pass it as a command-line argument.

$ python runserver 8080

If you want to change the server’s IP, pass it along with the port.

$ python runserver

Note that runserver is only for debug builds and local testing. Specialised server programs (such as Apache) should always be used in production.

Adding a Django App

A Django project usually contains multiple apps. This is simply a way to structure your project in smaller, maintainable modules. To create an app, go to your projectfolder (where is), and run the startapp command (change myapp to whatever you want):

python startapp myapp

This will generate the myapp folder and some necessary files for you, like and

In order to make Django aware of myapp, add it to your

# myproject/

# Application definition

The folder-structure of a Django project can be changed to fit your preference. Sometimes the project folder is renamed to /src to avoid repeating folder names. A typical folder structure looks like this:

directory structure