📄️ Web and HTTP Fundamentals
When you visit a website using your favorite browser (Firefox, Chrome, Edge, etc.), a connection is established through the Internet between a client, which initiates the connection and requests the content of the website, and a server, who accepts the connection and sends the requested content. Within a website we usually find different sections or pages and a multiplicity of multimedia content. Thus, the most common thing is that given a client request, the server responds with content in HTML format (embellished with CSS and JavaScript), although it can also respond with plain text, with an image, with JSON- or XML-formatted data, etc. Depending on the format in which the server transfers content, the web browser, which in this context is the client, interprets the information and shows you the proper page, or image, or document, etc.
📄️ Web Development With Python
Before moving forward with Django, it is important to ask ourselves what the role of Python in general is in this whole scheme that we have just introduced. When developing desktop applications (for example, using the tkinter standard module), you would usually design the graphical user interface (GUI, UI, or just "interface" for short) using Python functions and bind events that occur in the window (for example, a button press) to your own defined functions. This imples that both the graphical part and the logical part of a desktop application are developed with the same programming language and the same libraries.
📄️ About Django And Other Web Frameworks
Developing a web application with Python without using a web framework is like developing any program without using the standard library. Since Python is a multipurpose language, you do not have any modules specifically aimed at developing web applications in the standard library. You will then have to rely on some of these packages, the most popular being the following (in no particular order):
📄️ Setting up the Environment
Before we start, the first thing you need to do is, of course, install Django! You might do this either using a virtual environment or your global Python installation. We recommend to use a virtual environment.
📄️ A First Project
Projects vs. Applications
📄️ Views And URLs
Writing And Configuring Your First View
📄️ Response Types
Since we are developing a website, the content of the response that you return from a view will usually be in HTML format. Based on what we have seen so far, you could simply create the HTML code inside a view and pass it to HttpResponse like this: