› Forums › Web Development › HarvardX: CS50W – CS50’s Web Programming with Python and JavaScript › CS50W – Lecture 3 – Django › Understanding Why “encyclopedia/index.html” Is Not a Web Address in Django
- This topic is empty.
-
AuthorPosts
-
May 29, 2026 at 1:02 pm #6701
Understanding Why
"encyclopedia/index.html"Is Not a Web Address in DjangWhen learning Django, many beginners see code like:
return render(request, "encyclopedia/index.html", { "entries": util.list_entries() })and assume that:
encyclopedia/index.htmlis the URL that visitors will access in their browser.
However, that is not the case.
Template Path vs URL
The string:
"encyclopedia/index.html"is a template path, not a web address.
It tells Django which HTML template file to load from the server.
For example, Django may look for a file located at:
templates/ └── encyclopedia/ └── index.htmlDjango loads this template, inserts any dynamic data, and then generates the final HTML page that is sent to the browser.
What Determines the URL?
The URL is determined by
urls.py.For example:
from django.urls import path from . import views urlpatterns = [ path("", views.index, name="index"), ]Here, the URL:
/is connected to:
views.indexwhich then renders:
"encyclopedia/index.html"The Complete Flow
When a visitor opens:
http://127.0.0.1:8000/Django processes the request as follows:
Browser Request ↓ urls.py ↓ views.index(request) ↓ render(request, "encyclopedia/index.html", {...}) ↓ Load Template File ↓ Generate HTML ↓ Send HTML to BrowserKey Difference
Item Purpose /URL visited by the user views.indexView function that handles the request "encyclopedia/index.html"Template file used to build the page Restaurant Analogy
Think of Django like a restaurant:
- URL = Customer’s order
- View = Chef
- Template = Recipe
- Context Data = Ingredients
- HTML Page = Finished Meal
The customer never sees the recipe file directly. The chef uses the recipe to prepare the meal and serves the final result.
Similarly, visitors access URLs, while Django internally uses template files such as
encyclopedia/index.htmlto generate the web pages they see. -
AuthorPosts
- You must be logged in to reply to this topic.
