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.

Get updates
You will get emails when I publish something new or have something useful to share about making profitable digital businesses less brittle, less founder-dependent and easier to run.

Expect practical notes on backups, safer deploys, infrastructure as code, observability, documentation and automation. Usually no more than one email per week. You can unsubscribe at any time.

Für den Versand unserer Newsletter nutzen wir rapidmail. Mit Ihrer Anmeldung stimmen Sie zu, dass die eingegebenen Daten an rapidmail übermittelt werden. Beachten Sie bitte auch die AGB und Datenschutzbestimmungen .

vsupalov.com

© 2024 vsupalov.com. All rights reserved.