Python 3x Pandas Django

Getting Started with Django

Let’s learn by example.

Throughout this tutorial, we’ll walk you through the creation of an initial Django application.

We’ll assume you have Python & Django installed already. If it isn’t, you should see previous our section Django Introduction & System Setup

This tutorial is written for Django 3.2, which supports Python 3.6 and later. If the Django version doesn’t match, update Django to the newest version. If you’re using an older version of Python, check What Python version can I use with Django? to find a compatible version of Django.

Creating a project

If this is your first time using Django, you’ll have to take care of some initial setup. Namely, you’ll need to auto-generate some code that establishes a Django project – a collection of settings for an instance of Django, including database configuration, Django-specific options and application-specific settings.

From the command line, cd into a directory where you’d like to store your code, then run the following command:

django-admin startproject myfirstsite

startproject command

This will create a myfirstsite directory in your current directory.


Let’s look at what startproject created:

myfirstsite /
    myfirstsite /

These files are:

• The outer myfirstsite/ root directory is a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like.

• A command-line utility that lets you interact with this Django project in various ways. You can read all the details about in django-admin and

• The inner myfirstsite/ directory is the actual Python package for your project. Its name is the Python package name you’ll need to use to import anything inside it (e.g. myfirstsite.urls).

• myfirstsite/ An empty file that tells Python that this directory should be considered a Python package.

• myfirstsite/ Settings/configuration for this Django project. Django settings will tell you all about how settings work.

• myfirstsite/ The URL declarations for this Django project; a “table of contents” of your Django-powered site. (list of entry point to your site)

• myfirstsite/ An entry-point for ASGI-compatible web servers to serve your project. (This file will be used for deploying your site to live)

• myfirstsite/ An entry-point for WSGI-compatible web servers to serve your project (This file will be used for deploying your site to live)

Now, it’s a time to re-check this below diagram MVT request and response calls,

MVT Diagram

You’re going to see what happens when you type an address into your web browser and press Enter.

The first address point inside the Django app is the in the myfirstsite app. That file will direct you towards the in the app you want to go to. That will forward you to, where the code logic happens. The functions in there will direct you towards a specific template to render and return to the user to see in the browser.

If these lines are not clear. don't worry, you will see an example in the next session.

The development server

Let’s verify our Django project works.

The outer myfirstsite / root directory is a container for your project. Its name doesn’t matter to Django; you can rename it to anything you like. So, I am changing it to tutorial1.

changing directory name

And move into the outer tutorial1 directory

cd tutorial1

changed directory name to tutorial1

And run the following commands: (This command will start the development server)

python runserver

runserver command

You’ll see the following output on the command line:

Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).

You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python migrate' to apply them.
August 29, 2021 - 19:28:27
Django version 3.2.6, using settings 'myfirstsite.settings'
Starting development server at
Quit the server with CTRL-BREAK.

Note: Ignore the warning about unapplied database migrations for now; we’ll deal with the database shortly.

You’ve started the Django development server, a lightweight Web server written purely in Python. We’ve included this with Django so we can develop things rapidly, without having to deal with configuring a production server – such as Apache Tomcat – until you’re ready for production.

Now that the server’s running, visit with your Web browser. You’ll see a “Congratulations!” page, with a rocket taking off. It worked!

Congratulations Page

You will see an additional db.sqlite3 file created when we run command python runserver. We will see this file in the database session.


By default, the runserver command starts the development server on the internal IP at port 8000.

If you want to change the server’s port, pass it as a command-line argument. For instance, this command starts the server on port 8080:

python runserver 8080

If you want to change the server’s IP, pass it along with the port. For example, to listen on all available public IPs (which is useful if you want to show off your work on other computers on the network), use:

python runserver

The development server automatically reloads Python code for each request as needed. You don’t need to restart the server for code changes to take effect. However, some actions like adding new files don’t trigger a restart, so you’ll have to restart the server in these cases.

Congratulations! You have successfully completed initial Django application setup tutorial session.

If you have any doubts or queries related to this chapter, get them clarified from our Python Team experts on ibmmainframer Community!