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
Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards and optional settings files.

Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards in settings file paths and mark setti

Nikita Sobolev 940 Jan 03, 2023
A BitField extension for Django Models

django-bitfield Provides a BitField like class (using a BigIntegerField) for your Django models. (If you're upgrading from a version before 1.2 the AP

DISQUS 361 Dec 22, 2022
https://django-storages.readthedocs.io/

Installation Installing from PyPI is as easy as doing: pip install django-storages If you'd prefer to install from source (maybe there is a bugfix in

Josh Schneier 2.3k Jan 06, 2023
This is a Django app that uses numerous Google APIs such as reCAPTURE, maps and waypoints

Django project that uses Googles APIs to auto populate fields, display maps and routes for multiple waypoints

Bobby Stearman 57 Dec 03, 2022
REST API con Python, Django y MySQL (GET, POST, PUT, DELETE)

django_api_mysql REST API con Python, Django y MySQL (GET, POST, PUT, DELETE) REST API con Python, Django y MySQL (GET, POST, PUT, DELETE)

Andrew 1 Dec 28, 2021
AUES Student Management System Developed for laboratory works №9 Purpose using Python (Django).

AUES Student Management System (L M S ) AUES Student Management System Developed for laboratory works №9 Purpose using Python (Django). I've created t

ANAS NABIL 2 Dec 06, 2021
Indonesia's negative news detection using gaussian naive bayes with Django+Scikir Learn

Introduction Indonesia's negative news detection using gaussian naive bayes build with Django and Scikit Learn. There is also any features, are: Input

Harifzi Ham 1 Dec 30, 2021
This Django app will be used to host Source.Python plugins, sub-plugins, and custom packages.

Source.Python Project Manager This Django app will be used to host Source.Python plugins, sub-plugins, and custom packages. Want to help develop this

2 Sep 24, 2022
Strict separation of config from code.

Python Decouple: Strict separation of settings from code Decouple helps you to organize your settings so that you can change parameters without having

Henrique Bastos 2.3k Jan 04, 2023
Simple XML-RPC and JSON-RPC server for modern Django

django-modern-rpc Build an XML-RPC and/or JSON-RPC server as part of your Django project. Major Django and Python versions are supported Main features

Antoine Lorence 82 Dec 04, 2022
Reusable, generic mixins for Django

django-braces Mixins for Django's class-based views. Documentation Read The Docs Installation Install from PyPI with pip: pip install django-braces Bu

Brack3t 1.9k Jan 05, 2023
The Django Leaflet Admin List package provides an admin list view featured by the map and bounding box filter for the geo-based data of the GeoDjango.

The Django Leaflet Admin List package provides an admin list view featured by the map and bounding box filter for the geo-based data of the GeoDjango. It requires a django-leaflet package.

Vsevolod Novikov 33 Nov 11, 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-static-site - A simple content site framework that harnesses the power of Django without the hassle

coltrane A simple content site framework that harnesses the power of Django with

Adam Hill 57 Dec 06, 2022
A CTF leaderboard for the submission of flags during a CTF challenge. Built using Django.

🚩 CTF Leaderboard The goal of this project is to provide a simple web page to allow the participants of an CTF to enter their found flags. Also the l

Maurice Bauer 2 Jan 17, 2022
A small Django app to easily broadcast an announcement across a website.

django-site-broadcasts The site broadcast application allows users to define short messages and announcements that should be displayed across a site.

Ben Lopatin 12 Jan 21, 2020
webfest Django project @innovaccer

inno-doctor webfest Django project @innovaccer setup guide create new directory for project clone the repo with url into the directory make sure pytho

Rohit sahu 6 Oct 28, 2022
Analytics services for Django projects

django-analytical The django-analytical application integrates analytics services into a Django project. Using an analytics service with a Django proj

Jazzband 1.1k Dec 31, 2022
A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for quickly creating new images from the one assigned to the field.

django-versatileimagefield A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for creat

Jonathan Ellenberger 490 Dec 13, 2022
Advanced school management system written in Django :)

Advanced school management system written in Django :) ⚙️ Config the project First you should make venv for this project. So in the main root of proje

AminAli Mazarian 72 Dec 05, 2022