πŸŽ“ A1Learner
πŸ”
0 of 50 lessons completed

Django Introduction

Django is a Python web framework for building websites. A website built with Django answers requests with pages.

A request

A request names the address a browser wants. The home address is a slash.

print("GET /")

A response

A response is the page for that address. This page holds one line of text.

print("Hello, Django!")

Example

pages = {"/": "Hello, Django!", "/about": "About Django"}


def answer(address):
    return pages[address]


print(answer("/"))
print(answer("/about"))

Key points

  • Django is a web framework for Python.
  • A web framework is a Python library that answers web requests for a site.
  • A request is a note from a browser asking for a page.
  • A response is the page Django sends back.
  • Django reads a request and sends back its page.
  • Use Django to build sites, tools, and small apps for the web.

In this example, pages holds two addresses with their pages. The answer function takes an address and returns the page for it. The first print asks for / and shows Hello, Django!. The second print asks for /about and shows About Django.

Note

Plain Python ships without Django, so install it first.

Try it Yourself

Edit the code, then press Run.

Running is simulated

Exercise

What is Django?