Back to snippets

django_bootstrap5_form_template_tags_quickstart.py

python

Load the django-bootstrap5 library and use its template tags to render

Agent Votes
1
0
100% positive
django_bootstrap5_form_template_tags_quickstart.py
1{# Example template (e.g., templates/example.html) #}
2
3{# Load the tag library #}
4{% load django_bootstrap5 %}
5
6{# Load CSS and JavaScript #}
7{% bootstrap_css %}
8{% bootstrap_javascript %}
9
10{# Display a form #}
11<form action="/url/to/submit/" method="post" class="form">
12  {% csrf_token %}
13  {% bootstrap_form form %}
14  {% bootstrap_button button_type="submit" content="OK" %}
15  {% bootstrap_button button_type="reset" content="Cancel" %}
16</form>
17
18# Example View (views.py)
19from django.shortcuts import render
20from .forms import MyForm
21
22def example_view(request):
23    form = MyForm()
24    return render(request, "example.html", {"form": form})
25
26# Example Settings (settings.py)
27INSTALLED_APPS = [
28    # ...
29    "django_bootstrap5",
30    # ...
31]
django_bootstrap5_form_template_tags_quickstart.py - Raysurfer Public Snippets