Django application to add 'django-crispy-forms' layout objects for the GOV.UK Design System.
Project description
This is 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.
Install the package from PyPI:
pip install crispy-forms-gds
Add the app to your settings:
INSTALLED_APPS = ( ... 'crispy_forms_gds', ... )
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 app 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.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(TextInputForm, self).__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.
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
Read the documentation on Read the docs;
Download the PyPi package;
Clone the Github repository;
Learn more about Django Crispy Forms;
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for crispy_forms_gds-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4d6a1d650fdd113b85d2a246807c5f65db4b85789d6dff92f22f4c17f483685 |
|
MD5 | 2c6dcb97bcc8f4158d8c1bc836ee1485 |
|
BLAKE2b-256 | be3a01dc4a005c220003ef1de217da49b8e86527d074e9715a3f10117f2ebb53 |