How to Create a Dynamic Web App with Django


As a “batteries included” framework, Django provides everything you need to create a secure and easy-to-maintain web application.

Because Django abstracts away a lot of the low-level details, is well suited for beginners, though it’s highly regarded by experienced developers who can quickly develop working web applications with Django.

Django’s flexible enough that you can use it for everything from a simple website to a massive, complex project.

It’s best to know at least some basics of Python before learning Django. If you’ve not coded with Python before it’s an excellent language for beginners to learn, and there are a lot of excellent tutorials to help you get started.

Django’s a very popular web framework backed by a vibrant community, improving the software, writing documentation, and helping people solve problems.

Special note: consult HostAdvice’s  Best Python hosting and Best Django Hosting pages to find the leading web hosts in these categories, including expert and user reviews.

Before you start

This article assumes you have some knowledge of Python, have installed Python, and know how to create and use a virtual environment. These two articles can get you started setting up Python and learning Python: <how to install python and create a virtual environment> and <How to write your first Python scripts.>

Set your virtual environment

$ python3 -m venv virtenv
$ source virtenv/bin/activate

Install Django

First, use the pip package manager to install Django.

$ pip3 install django

You may want to upgrade pip at this point.

$ python3
>>> import django
>>> print(django.get_version()) # This should return the Django version number.

You’re now ready to build something using Django!

Create your Django project

You can call your project whatever you want, but it’s best to keep it simple. Change to the directory in which you’d like to create your project. For the purposes of this project we’ll created a directory for the project called web.

Start your Django project!

$ django-admin startproject website

This command will create a directory called hello and the initial project files. Do a directory listing to see what’s there.

You’ll find that Django created files in the current directory website and created another directory website with additional files. Here’s the structure.


The first website directory is the directory where you’re keeping your project. You can change the name to something else if you’d like.

You’ll use the utility to manage your application. Within the second website directory, tells Python what packages to use for this project. It starts out empty.

The script enables you to changed and add configuration settings to your project, lets you set the routes for URLs on your website, and (Web Server Gateway Interface) serves as the entry point for a web server so your site will serve content.

You’ll learn more details about all of these files and more as you work with Django, but now let’s try this thing out.

Test your Django server

$ python runserver

It should return something like the following.

Performing system checks...
System check identified no issues (0 silenced).
You have 14 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.
April 26, 2018 - 18:51:18
Django version 2.0.4, using settings 'website.settings'
Starting development server at
Quit the server with CONTROL-C.

Ignore the errors as you’re just testing your server. Enter into a browser address bar.

You’ve now successfully created a project and tested the server. The website project will now serve as the container in which you’ll create your apps.

Create your Django “Hello World” view

Making sure you’re in the directory containing, run the following command.

$ python startapp hello

This command will create a directory called hello for the hello app with this structure:


Open hello/ with your favorite editor. Add the following to then save the file.

from django.shortcuts import render
 # Create your views here.
# Note: The stuff above this will already be in this file.
from django.http import HttpResponse
def index(request):
    return HttpResponse("Hello, world!")

Next, create a URL configuration (called a url.conf) by adding a file named in the hello directory. Add the following code to hello/ and save the file.

from django.urls import path
from . import views
urlpatterns = [
    path('', views.index, name='index'),

Next, you’ll need modify the website url configuration by editing website/ Add the following code to the bottom.

from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('hello/', include('hello.urls')),

Start your server.

$ python runserver

Then enter this URL into a browser address bar:

If your web browser returns a simple “Hello World” you’ve successfully created your Django Hello world app! You’ve learned how to start a project, test your server, and create a simple working application.

The next article will help you build on this by creating an interactive app for this project.


Check out the top 3 Django hosting services:

  • Want to get top recommendations about best hosting? Just click this link!

Was this article helpful?