Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kevinbowen777/5cfa7dbc4c07dbf2b63519e335b74ec5 to your computer and use it in GitHub Desktop.
Save kevinbowen777/5cfa7dbc4c07dbf2b63519e335b74ec5 to your computer and use it in GitHub Desktop.
Django crispy forms implementation

Django crispy forms implementation - 20220424


  1. Install the package: poetry add django-crispy-forms OR pipenv install django-crispy-forms

  2. Add to INSTALLED_APPS:

#config/settings.py
INSTALLED_APPS = [
    "django.contrib.admin",
    ...,
    "django.contrib.staticfiles",
    # Third-party packages
    "crispy_forms",
    # Local applications
    ...,
]

# django-crispy-forms
CRISPY_TEMPLATE_PACK = "bootstrap4"
  1. Add to template forms
<!-- templates/registration/signup.html -->
{% extends '_base.html' %}
{% load crispy_forms_tags %}

{% block title %}Sign Up{% endblock title %}

{% block content %}
  <h2>Sign Up</h2>
  <form method="post">
    {% csrf_token %}
    {{ form|crispy }}
    <button class="btn btn-success" type="submit">Sign Up</button>
  </form>
{% endblock content %}
  1. Update login.html and other templates as necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment