templates

python
# Optional: custom error handlers
handler404 = 'myapp.views.custom_404'
handler500 = 'myapp.views.custom_500'


# In views.py

Django custom error pages (404, 500)

django python templates
by Priya Sharma 3 tabs
python
from django import template
from django.utils.safestring import mark_safe
import markdown

register = template.Library()

Django custom template filters for formatting

django python templates
by Priya Sharma 2 tabs
python
from django import template
from django.db.models import Count
from blog.models import Post, Tag

register = template.Library()

Django custom template tags for reusable components

django python templates
by Priya Sharma 2 tabs
python
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
from django.conf import settings


def send_welcome_email(user):

Django email with HTML templates

django python email
by Priya Sharma 1 tab
go
package web

import (
  "bytes"
  "html/template"
  "net/http"

Template rendering with html/template and strict escaping

go templates http
by Leah Thompson 1 tab
javascript
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["wrapper", "template", "anchor"]

  add(event) {

Stimulus: nested fields add/remove without re-rendering

rails stimulus hotwire
by codesnips 4 tabs
python
from django.conf import settings
from datetime import datetime


def site_settings(request):
    """Add site-wide settings to template context."""

Django context processors for global template variables

django python templates
by Priya Sharma 2 tabs