+91 81900 98289

Django Tutorial

This Django Tutorial lesson is for a beginner. Read the short notes, run each example, then change one name or number and run it again.

Django is a Python framework for sites that need pages, forms, and a database. A route maps a path to a function or a class.

This page cannot start a Django project. The example is the shape of a small route table.

Example 1: Start here

On your machine, django-admin startproject mysite creates the project folders.

routes = {"/courses/": "course_list", "/courses/python/": "course_detail"} # a dictionary; each key has one value print(routes["/courses/python/"])

Example 2: Map a path

Django Tutorial connects a web path to a name. The dictionary is the same idea as a Django route table.

routes = {"/courses/": "course_list", "/learn/": "Django Tutorial"} # a dictionary; each key has one value print(routes["/learn/"])

Example 3: Pick a missing path

A missing path should not crash the page. get returns the fallback text instead.

routes = {"/courses/": "course_list"} # a dictionary; each key has one value print(routes.get("/missing/", "not found")) # the fallback is used when the key is missing

Example 4: Build a small context

A Django view often sends a dictionary of values to the template. This is that dictionary.

context = {"title": "Django Tutorial", "seats": 21} # a dictionary; each key has one value print(context["title"], context["seats"]) # a comma prints each value, with a space between
On your machine, django-admin startproject mysite creates the project folders.
Call Now 81900 98289