Django Quick Start to Installation

April 22, 2020, 10:07 a.m.

Django Beginners · 3 min read

Django Quick Start to Installation

Last Modified: Sept. 11, 2020, 9:42 a.m.

Get started on your own Django web app using this Django quick start installation guide. It only takes a few minutes to get your Django project up and running on your local development server.

Follow the commands below and you'll soon see your Django web application running in your local browser window.

 

Create a virtual environment

macOS Terminal

User-Macbook:~ user$ cd desktop

User-Macbook:desktop user$ python3 -m venv env

User-Macbook:desktop user$ cd env

User-Macbook:env user$ source bin/activate

(env)User-Macbook:env user$

Windows Command Prompt

C:\Users\Owner> cd desktop

C:\Users\Owner\desktop> py -m venv env

C:\Users\Owner\desktop> cd env

C:\Users\Owner\desktop\env> Scripts\activate

(env)C:\Users\Owner\desktop\env>

Open the Windows Command Prompt or Mac Terminal and create a Python virtual environment, then activate it.

 

Install Django web framework

Django installation in macOS Terminal

(env)User-Macbook:env user$ pip install django

Django installation in Windows Command Prompt

(env)C:\Users\Owner\desktop\env> pip install django

Install django in your activated virtual environment.

 

Create the project using the startproject command

macOS Terminal

(env)User-Macbook:env user$ django-admin startproject mysite

Windows Command Prompt

(env)C:\Users\Owner\desktop\env> django-admin startproject mysite

Create a Django project named mysite.

 

If django-admin startproject mysite not working

If you run the command django-admin startproject mysite and it does not work:

  1. check to make sure your virtual environment is activated
  2. check that you are in the virtual environment folder
  3. make sure you properly installed Django in the virtual environment folder.  Run the command pip show django, to check if Django is installed or not. This command will show you the name of the package, version number, and other bits of information on the package.

 

Create the app using the startapp command

macOS Terminal

(env)User-Macbook:env user$ cd mysite

(env)User-Macbook:mysite user$ python3 manage.py startapp main

Windows Command Prompt

(env)C:\Users\Owner\desktop\env> cd mysite

(env)C:\Users\Owner\desktop\env\mysite> py manage.py startapp main

Enter into the mysite folder then create a Django application named main with the command python3 manage.py startapp main or py manage.py startapp main.

 

Run the development server

macOS Terminal

(env)User-Macbook:mysite user$ python3 manage.py runserver 
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
February 26, 2019 - 09:54:26
Django version 3.0.6, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-C.

Windows Command Prompt

(env) C:\Users\Owner\Desktop\Code\env\mysite>py manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).

You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them.
February 26, 2019 - 09:54:26
Django version 3.0.6, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-C.

Type the command python3 manage.py runsever for Mac and py manage.py runserver for Windows.

Note: You will always need to activate your virtual environment before running your local server. If you forget, you will get "module not found" errors.

 

Open the development server address in your browser

Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-C.

Look for the address http://127.0.0.1:8000/ above in the CLI then copy and paste this URL in a new browser window. A web page with a rocket will appear stating your installation was successful. To stop running the server, return to the CLI and enter the command Ctrl + C.

Django installation successful

Congratulations, you now have a Django project installed on your computer! From here, you can configure your web app to display your custom templates.


0
Subscribe now

Subscribe to stay current on our latest articles and promos





Post a Comment
Join the community

0 Comments