Skip to main content

Django application to add 'django-crispy-forms' layout objects for the GOV.UK Design System.

Project description

https://travis-ci.org/wildfish/crispy-forms-gds.svg?branch=master https://badge.fury.io/py/crispy-forms-gds.svg https://img.shields.io/pypi/pyversions/crispy-forms-gds.svg

A Django application to add django-crispy-forms template pack and layout objects for the GOV.UK Design System.

Install

This assumes you have already installed django-crispy-forms in your project. If not, the install guide is very simple.

  1. Install the package from PyPI:

    pip install crispy-forms-gds
  2. Add the app to your settings:

    INSTALLED_APPS = (
        ...
        'crispy_forms_gds',
        ...
    )
  3. Override the crispy_forms settings to set the template pack as the default:

    CRISPY_ALLOWED_TEMPLATE_PACKS = (
        "bootstrap", "bootstrap3", "bootstrap4", "uni_form", "gds"
    )
    CRISPY_TEMPLATE_PACK = "gds"

NOTE: The app does not include any GDS assets, you will have to install them in your project. Details are provided on the GOV.UK Design System site. Follow the Getting started guide and the installation instructions for a production install. The demo site has a webpack config file which you might find useful.

Example

To use the template pack just build a regular crispy form as before but the layout objects are imported from crispy_forms_gds:

from django import forms
from django.utils.translation import ugettext_lazy as _

from crispy_forms_gds.helper import FormHelper
from crispy_forms_gds.layout import Submit


class TextInputForm(forms.Form):

    name = forms.CharField(
        label=_("Name"),
        widget=forms.TextInput(),
        help_text=_("Your full name."),
        error_messages={
            "required": _("Enter your name as it appears on your passport")
        }
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.add_input(Submit("submit", _("Submit")))

And render the form in your templates:

{% load i18n crispy_forms_tags %}
...
{% crispy form %}
...

That’s it.

All in one

The template pack supports all the basic components listed in the GOV.UK Design System:

https://i.imgur.com/RCTUPrg.png

Demo

If you checkout the code from the repository, there is a Django site you can run to see the forms in action. You will need to install nvm for managing node versions first. After that build everything and run the demo with:

make serve

Requires

  • Django >=2.2;

  • django-crispy-forms >= 1.9.x;

Resources

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crispy-forms-gds-0.1.0.tar.gz (20.5 kB view hashes)

Uploaded Source

Built Distribution

crispy_forms_gds-0.1.0-py3-none-any.whl (30.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page