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
Chatbot for ordering and tracking a Pizza.

Pizza Chatbot To start the app, follow the below steps: Clone the repo using the below command: git clone Shreya Shah 1 Jul 15, 2021

Django + Next.js integration

Django Next.js Django + Next.js integration From a comment on StackOverflow: Run 2 ports on the same server. One for django (public facing) and one fo

Quera 162 Jan 03, 2023
Django API creation with signed requests utilizing forms for validation.

django-formapi Create JSON API:s with HMAC authentication and Django form-validation. Version compatibility See Travis-CI page for actual test results

5 Monkeys 34 Apr 04, 2022
Tutorial para o projeto negros.dev - A EssĂȘncia do Django

Negros Dev Tutorial para o site negros.dev Este projeto foi feito com: Python 3.8.9 Django 3.1.8 Bootstrap 4.0 Como rodar o projeto? Clone esse reposi

Regis Santos 6 Aug 12, 2022
django-compat-lint

django_compat_lint -- check Django compatibility of your code Django's API stability policy is nice, but there are still things that change from one v

James Bennett 40 Sep 30, 2021
TinyApp - A Python (Django) Full Stack Application for shortening URLs

TinyApp A Python (Django) Full Stack Application for shortening URLs. How to sta

Li Deng 1 Jan 23, 2022
Log and View requests made on Django

Django Request Viewer Log and view requests made on your Django App Introduction Recently, @ichtrojan and @toniastro released horus, a request logger

Akere Mukhtar 26 May 29, 2022
Imparare Django ricreando un sito facsimile a quello Flask

SitoPBG-Django Imparare Django ricreando un sito facsimile a quello Flask Note di utilizzo Necessita la valorizzazione delle seguenti variabili di amb

Mario Nardi 1 Dec 08, 2021
simple project management tool for educational purposes

Taskcamp This software is used for educational and demonstrative purposes. It's a simple project management tool powered by Django Framework Install B

Ilia Dmitriev 6 Nov 08, 2022
Django friendly finite state machine support

Django friendly finite state machine support django-fsm adds simple declarative state management for django models. If you need parallel task executio

Viewflow 2.1k Dec 31, 2022
Streamlining Django forms to provide all the wins of single-page-applications without the pain.

nango Streamlining Django forms to provide all the wins of single-page-applications without the pain. Key features Available to all Django deployments

Nick Farrell 107 Dec 12, 2022
Django's class-based generic views are awesome, let's have more of them.

Django Extra Views - The missing class-based generic views for Django Django-extra-views is a Django package which introduces additional class-based v

Andy Ingram 1.3k Jan 04, 2023
Forward and backwards compatibility layer for Django 1.4, 1.7, 1.8, 1.9, 1.10, and 1.11

django-compat Forward and backwards compatibility layer for Django 1.4 , 1.7 , 1.8, 1.9, 1.10 and 1.11 Consider django-compat as an experiment based o

arteria GmbH 106 Mar 28, 2022
Blog focused on skills enhancement and knowledge sharing. Tech Stack's: Vue.js, Django and Django-Ninja

Blog focused on skills enhancement and knowledge sharing. Tech Stack's: Vue.js, Django and Django-Ninja

Wanderson Fontes 2 Sep 21, 2022
Custom Django field for using enumerations of named constants

django-enumfield Provides an enumeration Django model field (using IntegerField) with reusable enums and transition validation. Installation Currently

5 Monkeys 195 Dec 20, 2022
Dockerizing Django with Postgres, Gunicorn, Nginx and Certbot. A fully Django starter project.

Dockerizing Django with Postgres, Gunicorn, Nginx and Certbot 🚀 Features A Django stater project with fully basic requirements for a production-ready

8 Jun 27, 2022
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
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
A Django/Python web app that functions as a digital diary

My Django Diary Full-stack web application that functions as a digital diary using Django, Python, SQLite, HTML & CSS. Things I learned during this pr

1 Sep 30, 2022
Source code for Django for Beginners 3.2

The official source code for https://djangoforbeginners.com/. Available as an ebook or in Paperback. If you have the 3.1 version, please refer to this

William Vincent 10 Jan 03, 2023