Django is a Python module for building web apps. Similar to Flask, but it comes with many more features. In Flask you can use any database system you want, but with Django you should use an Object-Relational Manager (ORM).

With Flask you have to choose everything yourself, it’s known as a micro-framework. Django on the other hand, is a complete framework which made many choices for you.

Regardless of your module choice, you can put your Python app online.

Python web app

After creating an account, you can choose “Add a new web app”.

python web app

This lets you choose between a variety of frameworks including Django, web2py, Flask, Bottle or custom ones.

django web app framework

Make sure to select the latest Python version. Finally choose a name for your project. After you click Next, your Python web app wil be immediately online.

django

However, the webpage shown is not the “hello world” one, but a default template.

django app

Django hello world

Hello world is one of the most basic apps you can make, all it does is display the message. In the context of web development, it means you open a link and see the message “hello world”.

A web app can have many different links, like /hello or /users. Each of those links can be connected to a view.

Change the file views.py with this content:

1
2
3
4
from django.http import HttpResponse

def helloView(request):
return HttpResponse("Hello, World!")

This function helloView will return a web response with the function HttpResponse. Link the function to a web call, by changing urls.py.

1
2
3
4
5
6
7
from django.contrib import admin
from django.urls import path
from .views import helloView

urlpatterns = [
path('', helloView, name='hello')
]

The function will be called when the path is ‘’, which means the domain name. You can put any path here like /hello or /example. The second parameter connects it to the helloView function in the other file.

Restart your Python server by clicking the green button and reopen the page, you’ll see the hello world message.

django hello world

What are the pros and cons of Django?

The advantages of Django

  • Full-featured and complete: comes with a large number of common tools and frameworks for enterprise web development (such as paging, auth, permission management), suitable for rapid development of enterprise-level websites.

  • Complete documentation After more than a decade of development and refinement, Django has a wide range of practical examples and complete online documentation. Developers can search the online documentation for solutions when they encounter problems.

  • Powerful database access layer: Django’s Model layer comes with a database ORM component, allowing developers to operate on databases without having to learn the SQL language.

django orm

  • app design philosophy: the idea that apps are pluggable is unparalleled. If you don’t need it anymore, you can just delete it and it won’t have much impact on the system as a whole.

  • django-admin system: A complete backend data management control platform can be achieved with just a few simple lines of configuration and code.

django amin system for databases

Disadvantages of Django

  • Over-encapsulation: Django includes modules that are not needed for lightweight applications, and is not as lightweight as Flask.

  • Performance disadvantages: Django’s performance is low compared to C and C++, but this is the fault of python and other python frameworks will have the same problem when the traffic comes up.

  • Template issues: django’s templates implement a complete separation of code and style, and do not allow python code to appear in templates, which may not be flexible enough for some programmers.