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
Django admin CKEditor integration.

Django CKEditor NOTICE: django-ckeditor 5 has backward incompatible code moves against 4.5.1. File upload support has been moved to ckeditor_uploader.

2.2k Jan 02, 2023
Django server-side adapter for Inertia.js

django-inertia Django server-side new adapter for Inertia.js. Getting Started Install the package pip install django-inertia Configure your project A

Samuel Girardin 14 Sep 16, 2022
An automatic django's update checker and MS teams notifier

Django Update Checker This is small script for checking any new updates/bugfixes/security fixes released in django News & Events and sending correspon

prinzpiuz 4 Sep 26, 2022
Template de desarrollo Django

Template de desarrollo Django Python Django Docker Postgres Nginx CI/CD Descripción del proyecto : Proyecto template de directrices para la estandariz

Diego Esteban 1 Feb 25, 2022
Bootstrap 4 integration with Django.

django-bootstrap 4 Bootstrap 4 integration for Django. Goal The goal of this project is to seamlessly blend Django and Bootstrap 4. Requirements Pytho

Zostera B.V. 980 Dec 29, 2022
open source online judge based on Vue, Django and Docker

An onlinejudge system based on Python and Vue

Qingdao University(青岛大学) 5.2k Jan 09, 2023
✋ Auto logout a user after specific time in Django

django-auto-logout Auto logout a user after specific time in Django. Works with Python 🐍 ≥ 3.7, Django 🌐 ≥ 3.0. ✔️ Installation pip install django-a

Georgy Bazhukov 21 Dec 26, 2022
Django React Flight Rezervation

Django Intro & Installation python -m venv venv source ./venv/Scripts/activate pip install Django pip install djangorestframework pip install python-d

HILMI SARIOGLU 2 May 26, 2022
Improved Django model inheritance with automatic downcasting

Polymorphic Models for Django Django-polymorphic simplifies using inherited models in Django projects. When a query is made at the base model, the inh

1.4k Jan 03, 2023
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 09, 2022
A helper for organizing Django project settings by relying on well established programming patterns.

django-configurations django-configurations eases Django project configuration by relying on the composability of Python classes. It extends the notio

Jazzband 953 Dec 29, 2022
Build reusable components in Django without writing a single line of Python.

Build reusable components in Django without writing a single line of Python. {% #quote %} {% quote_photo src="/project-hail-mary.jpg" %} {% #quot

Mitchel Cabuloy 277 Jan 02, 2023
Simpliest django(uvicorn)+postgresql+nginx docker-compose (ready for production and dev)

simpliest django(uvicorn)+postgresql+nginx docker-compose (ready for production and dev) To run in production: docker-compose up -d Site available on

Artyom Lisovskii 1 Dec 16, 2021
Docker django app

Hmmmmm... What I should write here? Maybe "Hello World". Hello World Build Docker compose: sudo docker-compose build Run Docker compose: sudo docker-

Andrew 0 Nov 10, 2022
🔃 A simple implementation of STOMP with Django

Django Stomp A simple implementation of STOMP with Django. In theory it can work with any broker which supports STOMP with none or minor adjustments.

Juntos Somos Mais 32 Nov 08, 2022
Simple tagging for django

django-taggit This is a Jazzband project. By contributing you agree to abide by the Contributor Code of Conduct and follow the guidelines. django-tagg

Jazzband 3k Jan 02, 2023
Declarative model lifecycle hooks, an alternative to Signals.

Django Lifecycle Hooks This project provides a @hook decorator as well as a base model and mixin to add lifecycle hooks to your Django models. Django'

Robert Singer 1k Dec 31, 2022
A Django web application to receive, virus check and validate transfers of digital archival records, and allow archivists to appraise and accession those records.

Aurora Aurora is a Django web application that can receive, virus check and validate transfers of digital archival records, and allows archivists to a

Rockefeller Archive Center 20 Aug 30, 2022
Transparently use webpack with django

Looking for maintainers This repository is unmaintained as I don't have any free time to dedicate to this effort. If you or your organisation are heav

Owais Lone 2.4k Jan 06, 2023
Django Persistent Filters is a Python package which provide a django middleware that take care to persist the querystring in the browser cookies.

Django Persistent Filters Django Persistent Filters is a Python package which provide a django middleware that take care to persist the querystring in

Lorenzo Prodon 2 Aug 05, 2022