Create:
mysite/
news/
templates/
news/
index.html
Converting Index to TemplateView and defining the template to be index.html
from django.views.generic import TemplateView
class Index(TemplateView):
template_name = 'news/index.html'
Some text for the template:
<h1>Hello World!</h1>
URLs (Routing)
To keep everything organized, we create a urls.py file for each app we create.
from django.urls import path
from news.views import *
urlpatterns = [
path('', Index.as_view(), name="index"),
]
Then it's a matter of including each app urls.py file in the main urls.py file.
from django.contrib import admin
from django.urls import path
from django.urls import include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('news.urls')),
]
Access through the browser:
http://localhost:8000/
Tested with Django 5.2
02 March 2023
|
Last Updated: 27 Dec. 2025
|
jaimedcsilva Related