Snippet: The Most Simple URL-Based View in Django
When starting a new Django project, I always like to get a first, simple view working.
It’s kind of a “Hello World” step I like to take.
If you have created and configured a templates folder, and created your
first template within it, all that’s left to do is to add two lines to
the project’s urls.py:
from django.contrib import admin
from django.urls import path
from django.views.generic.base import TemplateView # here
urlpatterns = [
path('admin/', admin.site.urls),
path('', TemplateView.as_view(template_name="base.html")), # and here
]
This will render the base.html template when the root of your
new project is visited. A first template-rendering class-based view.
A word from the author
Hi, I'm Vladislav. I work with small teams and bootstrapped founders who need to get their infrastructure right — reliable deployments, less operational risk, and systems that don't fall apart the moment the founder looks away. If that sounds like your situation, here's how we can work together.
I've been writing about Docker, deployment, and infrastructure since 2017. If you'd like to read more, the articles page is a good place to start — or you can sign up for the newsletter to get new pieces by email.