Tweak the form field rendering in templates, not in python-level form definitions. CSS classes and HTML attributes can be altered.

Overview

django-widget-tweaks

Jazzband PyPI Version GitHub Actions Coverage

Tweak the form field rendering in templates, not in python-level form definitions. Altering CSS classes and HTML attributes is supported.

That should be enough for designers to customize field presentation (using CSS and unobtrusive javascript) without touching python code.

License is MIT.

Installation

You can get Django Widget Tweaks by using pip:

$ pip install django-widget-tweaks

To enable widget_tweaks in your project you need to add it to INSTALLED_APPS in your projects settings.py file:

INSTALLED_APPS = [
    ...
    'widget_tweaks',
    ...
]

Usage

This app provides two sets of tools that may be used together or standalone:

  1. a render_field template tag for customizing form fields by using an HTML-like syntax.
  2. several template filters for customizing form field HTML attributes and CSS classes

The render_field tag should be easier to use and should make form field customizations much easier for designers and front-end developers.

The template filters are more powerful than the render_field tag, but they use a more complex and less HTML-like syntax.

render_field

This is a template tag that can be used as an alternative to aforementioned filters. This template tag renders a field using a syntax similar to plain HTML attributes.

Example:

{% load widget_tweaks %}

<!-- change input type (e.g. to HTML5) -->
{% render_field form.search_query type="search" %}

<!-- add/change several attributes -->
{% render_field form.text rows="20" cols="20" title="Hello, world!" %}

<!-- append to an attribute -->
{% render_field form.title class+="css_class_1 css_class_2" %}

<!-- template variables can be used as attribute values -->
{% render_field form.text placeholder=form.text.label %}

<!-- double colon -->
{% render_field form.search_query v-bind::class="{active:isActive}" %}

For fields rendered with {% render_field %} tag it is possible to set error class and required fields class by using WIDGET_ERROR_CLASS and WIDGET_REQUIRED_CLASS template variables:

{% with WIDGET_ERROR_CLASS='my_error' WIDGET_REQUIRED_CLASS='my_required' %}
    {% render_field form.field1 %}
    {% render_field form.field2 %}
    {% render_field form.field3 %}
{% endwith %}

You can be creative with these variables: e.g. a context processor could set a default CSS error class on all fields rendered by {% render_field %}.

attr

Adds or replaces any single html attribute for the form field.

Examples:

{% load widget_tweaks %}

<!-- change input type (e.g. to HTML5) -->
{{ form.search_query|attr:"type:search" }}

<!-- add/change several attributes -->
{{ form.text|attr:"rows:20"|attr:"cols:20"|attr:"title:Hello, world!" }}

<!-- attributes without parameters -->
{{ form.search_query|attr:"autofocus" }}


<!-- attributes with double colon Vuejs output: v-bind:class="{active:ValueEnabled}" -->
{{ form.search_query|attr:"v-bind::class:{active:ValueEnabled}" }}

add_class

Adds CSS class to field element. Split classes by whitespace in order to add several classes at once.

Example:

{% load widget_tweaks %}

<!-- add 2 extra css classes to field element -->
{{ form.title|add_class:"css_class_1 css_class_2" }}

set_data

Sets HTML5 data attribute ( http://ejohn.org/blog/html-5-data-attributes/ ). Useful for unobtrusive javascript. It is just a shortcut for 'attr' filter that prepends attribute names with 'data-' string.

Example:

{% load widget_tweaks %}

<!-- data-filters:"OverText" will be added to input field -->
{{ form.title|set_data:"filters:OverText" }}

append_attr

Appends attribute value with extra data.

Example:

{% load widget_tweaks %}

<!-- add 2 extra css classes to field element -->
{{ form.title|append_attr:"class:css_class_1 css_class_2" }}

'add_class' filter is just a shortcut for 'append_attr' filter that adds values to the 'class' attribute.

remove_attr

Removes any single html attribute for the form field.

Example:

{% load widget_tweaks %}

<!-- removes autofocus attribute from field element -->
{{ form.title|remove_attr:"autofocus" }}

add_label_class

The same as add_class but adds css class to form labels.

Example:

{% load widget_tweaks %}

<!-- add 2 extra css classes to field label element -->
{{ form.title|add_label_class:"label_class_1 label_class_2" }}

add_error_class

The same as 'add_class' but adds css class only if validation failed for the field (field.errors is not empty).

Example:

{% load widget_tweaks %}

<!-- add 'error-border' css class on field error -->
{{ form.title|add_error_class:"error-border" }}

add_error_attr

The same as 'attr' but sets an attribute only if validation failed for the field (field.errors is not empty). This can be useful when dealing with accessibility:

{% load widget_tweaks %}

<!-- add aria-invalid="true" attribute on field error -->
{{ form.title|add_error_attr:"aria-invalid:true" }}

add_required_class

The same as 'add_error_class' adds css class only for required field.

Example:

{% load widget_tweaks %}

<!-- add 'is-required' css class on field required -->
{{ form.title|add_required_class:"is-required" }}

field_type and widget_type

'field_type' and 'widget_type' are template filters that return field class name and field widget class name (in lower case).

Example:

{% load widget_tweaks %}

<div class="field {{ field|field_type }} {{ field|widget_type }} {{ field.html_name }}">
    {{ field }}
</div>

Output:

<div class="field charfield textinput name">
    <input id="id_name" type="text" name="name" maxlength="100" />
</div>

Mixing render_field and filters

The render_field tag and filters mentioned above can be mixed.

Example:

{% render_field form.category|append_attr:"readonly:readonly" type="text" placeholder="Category" %}

returns:

<input name="category" placeholder="Profession" readonly="readonly" type="text">

Filter chaining

The order django-widget-tweaks filters apply may seem counter-intuitive (leftmost filter wins):

{{ form.simple|attr:"foo:bar"|attr:"foo:baz" }}

returns:

<input foo="bar" type="text" name="simple" id="id_simple" />

It is not a bug, it is a feature that enables creating reusable templates with overridable defaults.

Reusable field template example:

{# inc/field.html #}
{% load widget_tweaks %}
<div>{{ field|attr:"foo:default_foo" }}</div>

Example usage:

{# my_template.html #}
{% load widget_tweaks %}
<form method='POST' action=''> {% csrf_token %}
    {% include "inc/field.html" with field=form.title %}
    {% include "inc/field.html" with field=form.description|attr:"foo:non_default_foo" %}
</form>

With 'rightmost filter wins' rule it wouldn't be possible to override |attr:"foo:default_foo" in main template.

Contributing

If you've found a bug, implemented a feature or have a suggestion, do not hesitate to contact me, fire an issue or send a pull request.

Testing

Make sure you have tox installed, then type

tox

from the source checkout.

NOT SUPPORTED

MultiWidgets: SplitDateTimeWidget, SplitHiddenDateTimeWidget

Comments
  • Is this project still being maintained?

    Is this project still being maintained?

    I'm relying on this for a couple of small django apps because I didn't find any viable alternatives.

    It appears as if the GitHub repository was moved sometime in the last year and since then nothing really happened.

    I'd be willing to consider maintaining it, if @jazzband doesn't want to.

    opened by simhnna 15
  • Do there any blockers to bump new release?

    Do there any blockers to bump new release?

    We are looking forward to using django-widget-tweaks with Django 3.2 on edX.

    Required PR - #112 is already merged into the master branch. Do there any chance a new version will be bumped soon?

    If any blockers with the release I would be happy to help.

    Thank you in advance.

    opened by jramnai 13
  • Implement Jazzband guidelines for project django-widget-tweaks

    Implement Jazzband guidelines for project django-widget-tweaks

    This issue tracks the implementation of the Jazzband guidelines for the project django-widget-tweaks

    It was initiated by @kmike who was automatically assigned in addition to the Jazzband roadies.

    See the TODO list below for the generally required tasks, but feel free to update it in case the project requires it.

    Feel free to ping a Jazzband roadie if you have any question.

    TODOs

    • [x] Fix all links in the docs (and README file etc) from old to new repo
    • [x] Add the Jazzband badge to the README file
    • [x] Add the Jazzband contributing guideline to the CONTRIBUTING.md file
    • [x] Check if continuous testing works (e.g. Travis-CI, CircleCI, AppVeyor, etc)
    • [x] Check if test coverage services work (e.g. Coveralls, Codecov, etc)
    • [x] Add jazzband account to PyPI project as maintainer role (URL: https://pypi.python.org/pypi?:action=role_form&package_name=<PROJECTNAME>)
    • [ ] Add jazzband-bot as maintainer to the Read the Docs project (URL: https://readthedocs.org/dashboard/<PROJECTNAME>/users/)
    • [x] Fix project URL in GitHub project description
    • [x] Review project if other services are used and port them to Jazzband

    Project details

    Description Tweak the form field rendering in templates, not in python-level form definitions. CSS classes and HTML attributes can be altered.
    Homepage
    Stargazers 730
    Open issues 27
    Forks 58
    Default branch master
    Is a fork False
    Has Wiki False
    Has Pages False
    opened by jazzband-bot 8
  • Can't override `type=

    Can't override `type="search"` for text field anymore

    Hi!

    I'm migrating my project from Django 1.9 to 1.11. I have the following code which was working great in Django 1.9 but doesn't work in Django 1.11:

    {% render_field form.q type='search' required='required' class='term-input' %}
    

    And here's my Django form:

    class SearchForm(forms.Form):
        q = forms.CharField(label='Search')
    

    Only if I explicitly override the field widget's type atribute - it works:

    class SearchForm(forms.Form):
        q = forms.CharField(label='Search', widget=TextInput(attrs={'type': 'search'}))
    

    Investigation

    AFAIU, Django 1.11 has moved widgets rendering from Python code into templates (which is 100% positive change IMO), but now they treat type attribute in a special way:

    {# django-1.11.7/django/forms/templates/django/forms/widgets/input.html #}
    <input type="{{ widget.type }}" name="{{ widget.name }}"{% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} />
    

    So when I override

    {% render_field form.q required='required' class='term-input' data-x=1 %}
    

    ... - everything works great, but not when I change type :(

    opened by kottenator 8
  • add_class on label

    add_class on label

    It would be nice to have add_class be able to accept field labels.

    See https://bitbucket.org/kmike/django-widget-tweaks/issues/6/not-able-to-add-class-on-label

    opened by kevinmickey 8
  • NO remove_attr filter in the latest release

    NO remove_attr filter in the latest release

    I see you have pulled the remove_attr filter in the master branch but have not released that version. Kindly release a new version so we can have that by default. Thanks

    opened by ZeroCoolHacker 6
  • attr doesn't replace type

    attr doesn't replace type

    I have {{ field|add_class:"mdl-textfield__input"|attr:"type:date"}} and I expected <input type="date" name="start_date" value="2016-07-08" class="mdl-textfield__input" required id="id_start_date"> but in fact it produced <input type="text" name="start_date" value="2016-07-08" type="date" class="mdl-textfield__input" required id="id_start_date"> (notice the two types, with Google Chrome ignoring the second type)

    enhancement 
    opened by TurnrDev 6
  • shallow copy fields instead of deep copying

    shallow copy fields instead of deep copying

    Shallow copying is more efficient and still resolves the original issue due to which copying was introduced (#17).

    Deep copying of a field can fail due to a number of reasons, such as:

    1. Fields often indirectly refer to models. A model with relationship fields uses transient cache attributes which can change during the copying, resulting in a run-time error.
    2. Fields can have direct or indirect references to objects which cannot be copied, such as HTTP request objects.
    opened by kunkku 6
  • bug report: IOError: [Errno 2] No such file or directory: 'README.rst' when run command

    bug report: IOError: [Errno 2] No such file or directory: 'README.rst' when run command "python setup.py bdist_rpm"

    DONE: the bug is disappeared in your latest commit as manifest.in involved. IOError: [Errno 2] No such file or directory: 'README.rst' when run command "python setup.py bdist_rpm"

    opened by vitan 6
  • 'widget_tweaks' is not a valid tag library

    'widget_tweaks' is not a valid tag library

    Trying to use v 1.4.1 with Python 2.7 and 3.4 I can't get it working in Django 1.8 Always receiving: 'widget_tweaks' is not a valid tag library: Template library widget_tweaks not found on {% load widget_tweaks %} Any help?

    And yes, it is enabled in my INSTALLES_APPS section in the settings.py

    opened by greldinard 5
  • object.__new__(cStringIO.StringO) is not safe, use cStringIO.StringO.__new__()

    object.__new__(cStringIO.StringO) is not safe, use cStringIO.StringO.__new__()

    Version 1.3 works fine, this only happens in 1.4.

    ERROR Internal Server Error: /basket/
    Traceback (most recent call last):
      File "/virtenvs/test/lib/python2.7/site-packages/django/core/handlers/base.py", line 164, in get_response
        response = response.render()
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/response.py", line 158, in render
        self.content = self.rendered_content
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/response.py", line 135, in rendered_content
        content = template.render(context, self._request)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/backends/django.py", line 74, in render
        return self.template.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 209, in render
        return self._render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 201, in _render
        return self.nodelist.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/loader_tags.py", line 135, in render
        return compiled_parent._render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 201, in _render
        return self.nodelist.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/loader_tags.py", line 135, in render
        return compiled_parent._render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 201, in _render
        return self.nodelist.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/loader_tags.py", line 65, in render
        result = block.nodelist.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/loader_tags.py", line 65, in render
        result = block.nodelist.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/loader_tags.py", line 65, in render
        result = block.nodelist.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/loader_tags.py", line 159, in render
        return template.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 211, in render
        return self._render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 201, in _render
        return self.nodelist.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/defaulttags.py", line 329, in render
        return nodelist.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/loader_tags.py", line 56, in render
        result = self.nodelist.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/defaulttags.py", line 217, in render
        nodelist.append(node.render(context))
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/defaulttags.py", line 576, in render
        return self.nodelist.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/base.py", line 903, in render
        bit = self.render_node(node, context)
      File "/virtenvs/test/lib/python2.7/site-packages/django/template/debug.py", line 79, in render_node
        return node.render(context)
      File "/virtenvs/test/lib/python2.7/site-packages/widget_tweaks/templatetags/widget_tweaks.py", line 196, in render
        bounded_field = append_attr(bounded_field, '%s:%s' % (k,v.resolve(context)))
      File "/virtenvs/test/lib/python2.7/site-packages/widget_tweaks/templatetags/widget_tweaks.py", line 15, in wrapped
        return fn(field, attr)
      File "/virtenvs/test/lib/python2.7/site-packages/widget_tweaks/templatetags/widget_tweaks.py", line 77, in append_attr
        return _process_field_attributes(field, attr, process)
      File "/virtenvs/test/lib/python2.7/site-packages/widget_tweaks/templatetags/widget_tweaks.py", line 31, in _process_field_attributes
        field = copy.deepcopy(field)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
        y = _reconstruct(x, rv, 1, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
        state = deepcopy(state, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
        y = copier(x, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
        y[deepcopy(key, memo)] = deepcopy(value, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
        y = _reconstruct(x, rv, 1, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
        state = deepcopy(state, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
        y = copier(x, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
        y[deepcopy(key, memo)] = deepcopy(value, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
        y = _reconstruct(x, rv, 1, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
        state = deepcopy(state, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
        y = copier(x, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
        y[deepcopy(key, memo)] = deepcopy(value, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
        y = _reconstruct(x, rv, 1, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
        state = deepcopy(state, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
        y = copier(x, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
        y[deepcopy(key, memo)] = deepcopy(value, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
        y = _reconstruct(x, rv, 1, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
        state = deepcopy(state, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
        y = copier(x, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
        y[deepcopy(key, memo)] = deepcopy(value, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
        y = _reconstruct(x, rv, 1, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
        state = deepcopy(state, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
        y = copier(x, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
        y[deepcopy(key, memo)] = deepcopy(value, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
        y = _reconstruct(x, rv, 1, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 334, in _reconstruct
        state = deepcopy(state, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
        y = copier(x, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 237, in _deepcopy_tuple
        y.append(deepcopy(a, memo))
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 163, in deepcopy
        y = copier(x, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 257, in _deepcopy_dict
        y[deepcopy(key, memo)] = deepcopy(value, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 190, in deepcopy
        y = _reconstruct(x, rv, 1, memo)
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 329, in _reconstruct
        y = callable(*args)
      File "/virtenvs/test/bin/../lib/python2.7/copy_reg.py", line 93, in __newobj__
        return cls.__new__(cls, *args)
    TypeError: object.__new__(cStringIO.StringO) is not safe, use cStringIO.StringO.__new__()
    Traceback (most recent call last):
      File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
        self.result = application(self.environ, self.start_response)
      File "/virtenvs/test/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
        return self.application(environ, start_response)
      File "/virtenvs/test/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 189, in __call__
        response = self.get_response(request)
      File "/virtenvs/test/lib/python2.7/site-packages/django/core/handlers/base.py", line 218, in get_response
        response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
      File "/virtenvs/test/lib/python2.7/site-packages/django/core/handlers/base.py", line 261, in handle_uncaught_exception
        return debug.technical_500_response(request, *exc_info)
      File "/virtenvs/test/lib/python2.7/site-packages/django/views/debug.py", line 97, in technical_500_response
        html = reporter.get_traceback_html()
      File "/virtenvs/test/lib/python2.7/site-packages/django/views/debug.py", line 383, in get_traceback_html
        c = Context(self.get_traceback_data(), use_l10n=False)
      File "/virtenvs/test/lib/python2.7/site-packages/django/views/debug.py", line 328, in get_traceback_data
        frames = self.get_traceback_frames()
      File "/virtenvs/test/lib/python2.7/site-packages/django/views/debug.py", line 501, in get_traceback_frames
        'vars': self.filter.get_traceback_frame_variables(self.request, tb.tb_frame),
      File "/virtenvs/test/lib/python2.7/site-packages/django/views/debug.py", line 234, in get_traceback_frame_variables
        cleansed[name] = self.cleanse_special_types(request, value)
      File "/virtenvs/test/lib/python2.7/site-packages/django/views/debug.py", line 191, in cleanse_special_types
        value = self.get_request_repr(value)
      File "/virtenvs/test/lib/python2.7/site-packages/django/views/debug.py", line 122, in get_request_repr
        return build_request_repr(request, POST_override=self.get_post_parameters(request))
      File "/virtenvs/test/lib/python2.7/site-packages/django/views/debug.py", line 186, in get_post_parameters
        return request.POST
      File "/virtenvs/test/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 137, in _get_post
        self._load_post_and_files()
      File "/virtenvs/test/lib/python2.7/site-packages/django/http/request.py", line 246, in _load_post_and_files
        if self.method != 'POST':
    AttributeError: 'WSGIRequest' object has no attribute 'method'
    
    opened by phedoreanu 5
  • removing

    removing "required" from form-check-input

    This is for Firefox browser. In forms, added required=False in both forms.CharField(required=False) and forms.BooleanField(required=False). Checked Firefox inspector. For CharField, the "required" is not added and can be submitted without adding a text. For BooleanField, the required is added as required='False'. This still cause an error and not allow to enter without check. If the required='False' is removed via Firefox Inspector, it allows to enter without check. Why doesn't required='False' not work? Why does it add required='False' for BooleanField instead of removing "required" like in CharField?

    opened by edkim8 0
  • add another filter add_valid_class?

    add another filter add_valid_class?

    bootstrap allows the use of is-valid and is-invalid for fields of validated forms (bounded). Whereas is-invalid class can be easily added as

     {% render_field form.field1|add_error_class:'is-invalid' %}
    

    It is not easy to do so with is-valid because blindly adding the class will mark fields as valid for unbounded forms.

    Is it possible to add another filter called add_valid_class as follows?

    @register.filter("add_valid_class")
    @silence_without_field
    def add_valid_class(field, css_class):
        if field.form.is_bound and not (hasattr(field, "errors") and field.errors):
            return add_class(field, css_class)
        return 
    

    I suppose it also makes sense to add WIDGET_VALID_CLASS so that I can do

    {% with WIDGET_ERROR_CLASS='is-invalid' WIDGET_VALID_CLASS="is-valid" %}
        {% render_field form.field1 %}
        {% render_field form.field2 %}
        {% render_field form.field3 %}
    {% endwith %}
    
    opened by BoPeng 0
  • Add support for fields with subwidgets (BoundWidget)

    Add support for fields with subwidgets (BoundWidget)

    It's quite a simple addition.

    There is one disadvantage to this approach, which is that it assumes that the subfield will only be rendered with_label=False. I did this because it's a simple matter to attach a label using the template, and I'm not sure, but I think the implementation would otherwise have to be more complex.

    opened by johncronan 3
  • accessing variables in render_field tag

    accessing variables in render_field tag

    Hello I am using widget tweaks with bootstrap. I would like to set the size of the widget to the same value as maxlength. I am rather new in python and I could not find out how to do it in the documentation. If you could provide an example on how to access the value of an attribute of a field in a render field that would be helpful

    opened by piscvau 0
Releases(1.4.12)
Owner
Jazzband
Jazzband
Full control of form rendering in the templates.

django-floppyforms Full control of form rendering in the templates. Authors: Gregor Müllegger and many many contributors Original creator: Bruno Renié

Jazzband 811 Dec 1, 2022
Full control of form rendering in the templates.

django-floppyforms Full control of form rendering in the templates. Authors: Gregor Müllegger and many many contributors Original creator: Bruno Renié

Jazzband 811 Dec 1, 2022
MAC address Model Field & Form Field for Django apps

django-macaddress MAC Address model and form fields for Django We use netaddr to parse and validate the MAC address. The tests aren't complete yet. Pa

null 49 Sep 4, 2022
Resolve form field arguments dynamically when a form is instantiated

django-forms-dynamic Resolve form field arguments dynamically when a form is instantiated, not when it's declared. Tested against Django 2.2, 3.2 and

DabApps 108 Jan 3, 2023
Bleach is an allowed-list-based HTML sanitizing library that escapes or strips markup and attributes

Bleach Bleach is an allowed-list-based HTML sanitizing library that escapes or strips markup and attributes. Bleach can also linkify text safely, appl

Mozilla 2.5k Dec 29, 2022
This "I P L Team Project" is developed by Prasanta Kumar Mohanty using Python with Django web framework, HTML & CSS.

I-P-L-Team-Project This "I P L Team Project" is developed by Prasanta Kumar Mohanty using Python with Django web framework, HTML & CSS. Screenshots HO

null 1 Dec 15, 2021
Fully reponsive Chat Application built with django, javascript, materialUi, bootstrap4, html and css.

Chat app (Full Stack Frameworks with Django Project) Fully reponsive Chat Application built with django, javascript, materialUi, bootstrap4, html and

null 1 Jan 19, 2022
Basic Form Web Development using Python, Django and CSS

thebookrain Basic Form Web Development using Python, Django and CSS This is a basic project that contains two forms - borrow and donate. The form data

Ananya Dhulipala 1 Nov 27, 2021
A django model and form field for normalised phone numbers using python-phonenumbers

django-phonenumber-field A Django library which interfaces with python-phonenumbers to validate, pretty print and convert phone numbers. python-phonen

Stefan Foulis 1.3k Dec 31, 2022
A django model and form field for normalised phone numbers using python-phonenumbers

django-phonenumber-field A Django library which interfaces with python-phonenumbers to validate, pretty print and convert phone numbers. python-phonen

Stefan Foulis 1.3k Dec 31, 2022
Django-Text-to-HTML-converter - The simple Text to HTML Converter using Django framework

Django-Text-to-HTML-converter This is the simple Text to HTML Converter using Dj

Nikit Singh Kanyal 6 Oct 9, 2022
An extremely fast JavaScript and CSS bundler and minifier

Website | Getting started | Documentation | Plugins | FAQ Why? Our current build tools for the web are 10-100x slower than they could be: The main goa

Evan Wallace 34.2k Jan 4, 2023
Compresses linked and inline javascript or CSS into a single cached file.

Django Compressor Django Compressor processes, combines and minifies linked and inline Javascript or CSS in a Django template into cacheable static fi

null 2.6k Jan 3, 2023
Packs a bunch of smaller CSS files together from 1 folder.

Packs a bunch of smaller CSS files together from 1 folder.

null 1 Dec 9, 2021
Use heroicons in your Django and Jinja templates.

heroicons Use heroicons in your Django and Jinja templates. Requirements Python 3.6 to 3.9 supported. Django 2.2 to 3.2 supported. Are your tests slow

Adam Johnson 52 Dec 14, 2022
Location field and widget for Django. It supports Google Maps, OpenStreetMap and Mapbox

django-location-field Let users pick locations using a map widget and store its latitude and longitude. Stable version: django-location-field==2.1.0 D

Caio Ariede 481 Dec 29, 2022
This is a template tag project for django to calculate in templates , enjoy it

Calculator-Template-Django this is a template tag project for django to calculate in templates , enjoy it Get Started : 1 - Download Source Code 2 - M

null 1 Feb 1, 2022
A Django application that provides country choices for use with forms, flag icons static files, and a country field for models.

Django Countries A Django application that provides country choices for use with forms, flag icons static files, and a country field for models. Insta

Chris Beaven 1.2k Jan 7, 2023
A Django application that provides country choices for use with forms, flag icons static files, and a country field for models.

Django Countries A Django application that provides country choices for use with forms, flag icons static files, and a country field for models. Insta

Chris Beaven 1.2k Dec 31, 2022