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
This is a personal django website for forum posts

Django Web Forum This is a personal django website for forum posts It includes login, registration and forum posts with date time. Tech / Framework us

5 May 12, 2022
WeatherApp - Simple Python Weather App

Weather App Please star this repo if you like ⭐ It's motivates me a lot! Stack A

Ruslan Shvetsov 3 Apr 18, 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
Stream Framework is a Python library, which allows you to build news feed, activity streams and notification systems using Cassandra and/or Redis. The authors of Stream-Framework also provide a cloud service for feed technology:

Stream Framework Activity Streams & Newsfeeds Stream Framework is a Python library which allows you to build activity streams & newsfeeds using Cassan

Thierry Schellenbach 4.7k Jan 02, 2023
Django Starter is a simple Skeleton to start with a Django project.

Django Starter Template Description Django Starter is a simple Skeleton to start

Numan Ibn Mazid 1 Jan 10, 2022
PWA is a simple Django app to develope and deploy a Progressive Web Application.

PWA PWA is a simple Django app to develope and deploy a Progressive Web Application. Detailed documentation is in the "docs" directory. Quick start Ad

Nima 6 Dec 09, 2022
A Django web application that allows you to be in the loop about everything happening in your neighborhood.

A Django web application that allows you to be in the loop about everything happening in your neighborhood. From contact information of different handyman to meeting announcements or even alerts.

Kennedy Ngugi Mwaura 3 Dec 11, 2022
With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials.

Django Hijack With Django Hijack, admins can log in and work on behalf of other users without having to know their credentials. Docs 3.x docs are avai

1.2k Jan 05, 2023
Comparing Database performance with Django ORM

Comparing Database performance with Django ORM Postgresql MySQL MariaDB SQLite Comparing database operation performance using django ORM. PostgreSQL v

Sarath ak 21 Nov 14, 2022
A pluggable Django application for integrating PayPal Payments Standard or Payments Pro

Django PayPal Django PayPal is a pluggable application that integrates with PayPal Payments Standard and Payments Pro. See https://django-paypal.readt

Luke Plant 672 Dec 22, 2022
An app that allows you to add recipes from the dashboard made using DJango, JQuery, JScript and HTMl.

An app that allows you to add recipes from the dashboard. Then visitors filter based on different categories also each ingredient has a unique page with their related recipes.

Pablo Sagredo 1 Jan 31, 2022
Reusable workflow library for Django

django-viewflow Viewflow is a lightweight reusable workflow library that helps to organize people collaboration business logic in django applications.

Viewflow 2.3k Jan 08, 2023
Book search Django web project that uses requests python library and openlibrary API.

Book Search API Developer: Vladimir Vojtenko Book search Django web project that uses requests python library and openlibrary API. #requests #openlibr

1 Dec 08, 2021
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
A reusable Django model field for storing ad-hoc JSON data

jsonfield jsonfield is a reusable model field that allows you to store validated JSON, automatically handling serialization to and from the database.

Ryan P Kilby 1.1k Jan 03, 2023
Neighbourhood - A python-django web app to help the residence of a given neighborhood know their surrounding better

Neighbourhood A python-django web app to help the residence of a given neighborh

Levy Omolo 4 Aug 25, 2022
Django-fast-export - Utilities for quickly streaming CSV responses to the client

django-fast-export Utilities for quickly streaming CSV responses to the client T

Matthias Kestenholz 4 Aug 24, 2022
Template for Django Project Using Docker

You want a Django project who use Docker and Docker-compose for Development and for Production ? It's for you !

1 Dec 17, 2021
Exemplo de biblioteca com Django

Bookstore Exemplo de biblioteca feito com Django. Este projeto foi feito com: Python 3.9.7 Django 3.2.8 Django Rest Framework 3.12.4 Bootstrap 4.0 Vue

Regis Santos 1 Oct 28, 2021
Bootstrap 3 integration with Django.

django-bootstrap3 Bootstrap 3 integration for Django. Goal The goal of this project is to seamlessly blend Django and Bootstrap 3. Want to use Bootstr

Zostera B.V. 2.3k Jan 02, 2023