Setting Up A Simple Django Application
Here is a step by step guide for setting up a Django application.
Django is a high-level Python Web framework. It’s free and open source. It is fast, secure and scalable. This tutorial walks new programmers through the process of setting up their first Python and Django environment.
Step 1: Python
Django is a Python Web framework. You need python to start the development using Django.
Get the latest version of Python at https://www.python.org/downloads/
Download Latest version and install it.
Step 2: PIP
pip is a package management system used to install and manage software packages written in Python. Easiest and recommended way to install Django is with PIP.
If you already have pip installed, you might need to update it if it’s outdated.
pip install --upgrade pip
For fresh install use this https://pip.pypa.io/en/latest/installing/#installing-with-get-pip-py
To check, run this command
Step 3: Install Django
Using pip we will install the Django
Run this command
pip3 install django
This will install the Django Framework on your system. To check the Django version run
python3 -m django --version
Step 4: Creating a project
cd into a directory where you’d like to store your code, then run the following command:
django-admin startproject myFirstSite
cd into /myFirstSite and ls to see
Open this in your favorite Editor. I am using Sublime
Step 5: Directory Structure
- The outer myFirstSite/ is the container for your project.
- manage.py is a command-line utility that lets you interact with this Django project.
- The inner myFirstSite/ directory is the actual Python package for your project
- settings.py holds the settings/configuration for this Django project.
- urls.py holds the URL declarations for this Django project; a “table of contents” of your Django-powered site.
- wsgi.py is an entry-point for WSGI-compatible web servers to serve your project.
Step 6: Run
To verify your Django project works, cd into the outer myFirstSite directory and run this command
python3 manage.py runserver
You can ignore those warnings for now. They are related to the Database.
Now that the server’s running, visit http://127.0.0.1:8000/ with your Web browser. You’ll see a “Congratulations!” page, with a rocket taking off.