DJango startup commands

DJango startup commands

Hi! I have been learning django these days. I came across some basic commands that every beginner should know about. 

Whenever I work on a python project I prefer (and recommend) to work in a virtual environment. For virtual environment you may either use virtualenv, virtualenvwrapper, but I prefer pipenv. More detail about all three of them is available here.

To start a project in django first make a directory say “project” and change directory into it.

$ mkdir project && cd project

Now install django through “pipenv”:

$ pipenv install django

After django is installed, start the virtual environment with:

$ pipenv shell

Then start the project:

$ django-admin startproject newsite

The output of “tree” in the project directory would be like:

$ tree
├── newsite
│   ├──
│   └── newsite
│   ├──
│   ├──
│   ├──
│   └──
├── Pipfile
└── Pipfile.lock

2 directories, 7 files

Now get into the “newsite” directory just created:

$ cd newsite

Now populate the basic database with:

$ python migrate

or as is executable you may go with

$ ./ migrate

A new database (db.sqlite3) file in the directory would be created.

Now run the web app with:

$ python runserver

You may go to your localhost IP to check your empty django project working.

To make an app inside your project, you must be inside “newsite” directory (where is present). To create an app use:

$ python startapp newsite_app1

If you’ll make some models inside your “newsite_app1” and want to create corresponding database tables inside your django project database, then you’ll need to makemigrations and migrate your models with:

$ python makemigrations $ python migrate

If you’ll have to go to the admin panel of your django app by appending “/admin” in the localhost URL (i.e Here you’ll need a username and password to log in. For this, first create a superuser (admin) for mysite.

$ python createsuperuser
Username (leave blank to use 'shiva'): 
Email address:
Password (again): 
Superuser created successfully.

I’m keeping this post short. For any query and suggestions to improve this post with more django commands and usage of, please feel free to write in the comments section below.

Thanks for reading!



One thought on “DJango startup commands

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s