def render_field(<EOL>field, form, form_style, context, template=None, labelclass=None,<EOL>layout_object=None, attrs=None, template_pack=TEMPLATE_PACK,<EOL>extra_context=None, **kwargs<EOL>):
added_keys = [] if extra_context is None else extra_context.keys()<EOL>with KeepContext(context, added_keys):<EOL><INDENT>if field is None:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>FAIL_SILENTLY = getattr(settings, '<STR_LIT>', True)<EOL>if hasattr(field, '<STR_LIT>'):<EOL><INDENT>return field.render(<EOL>form, form_style, context, template_pack=template_pack,<EOL>)<EOL><DEDENT>else:<EOL><INDENT>if PY2:<EOL><INDENT>try:<EOL><INDENT>if isinstance(field, text_type):<EOL><INDENT>field = field.encode('<STR_LIT:ascii>').decode()<EOL><DEDENT>else:<EOL><INDENT>field = text_type(field)<EOL><DEDENT><DEDENT>except (UnicodeEncodeError, UnicodeDecodeError):<EOL><INDENT>raise Exception("<STR_LIT>" % field)<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>bound_field = form[field]<EOL>field_instance = bound_field.field<EOL>if attrs is not None:<EOL><INDENT>widgets = getattr(field_instance.widget, '<STR_LIT>', [field_instance.widget])<EOL>list_attrs = attrs<EOL>if isinstance(attrs, dict):<EOL><INDENT>list_attrs = [attrs] * len(widgets)<EOL><DEDENT>for index, (widget, attr) in enumerate(zip(widgets, list_attrs)):<EOL><INDENT>if hasattr(field_instance.widget, '<STR_LIT>'):<EOL><INDENT>if '<STR_LIT:type>' in attr and attr['<STR_LIT:type>'] == "<STR_LIT>":<EOL><INDENT>field_instance.widget.widgets[index] = field_instance.hidden_widget(attr)<EOL><DEDENT>else:<EOL><INDENT>field_instance.widget.widgets[index].attrs.update(attr)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if '<STR_LIT:type>' in attr and attr['<STR_LIT:type>'] == "<STR_LIT>":<EOL><INDENT>field_instance.widget = field_instance.hidden_widget(attr)<EOL><DEDENT>else:<EOL><INDENT>field_instance.widget.attrs.update(attr)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>except KeyError:<EOL><INDENT>if not FAIL_SILENTLY:<EOL><INDENT>raise Exception("<STR_LIT>" % field)<EOL><DEDENT>else:<EOL><INDENT>field_instance = None<EOL>logging.warning("<STR_LIT>" % field, exc_info=sys.exc_info())<EOL><DEDENT><DEDENT>if hasattr(form, '<STR_LIT>'):<EOL><INDENT>if not field in form.rendered_fields:<EOL><INDENT>form.rendered_fields.add(field)<EOL><DEDENT>else:<EOL><INDENT>if not FAIL_SILENTLY:<EOL><INDENT>raise Exception("<STR_LIT>" % field)<EOL><DEDENT>else:<EOL><INDENT>logging.warning("<STR_LIT>" % field, exc_info=sys.exc_info())<EOL><DEDENT><DEDENT><DEDENT>if field_instance is None:<EOL><INDENT>html = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>if template is None:<EOL><INDENT>if form.crispy_field_template is None:<EOL><INDENT>template = default_field_template(template_pack)<EOL><DEDENT>else:   <EOL><INDENT>template = get_template(form.crispy_field_template)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>template = get_template(template)<EOL><DEDENT>if layout_object is not None:<EOL><INDENT>if hasattr(layout_object, '<STR_LIT>') and isinstance(layout_object.bound_fields, list):<EOL><INDENT>layout_object.bound_fields.append(bound_field)<EOL><DEDENT>else:<EOL><INDENT>layout_object.bound_fields = [bound_field]<EOL><DEDENT><DEDENT>context.update({<EOL>'<STR_LIT>': bound_field,<EOL>'<STR_LIT>': labelclass,<EOL>'<STR_LIT>': flatatt(attrs if isinstance(attrs, dict) else {}),<EOL>})<EOL>if extra_context is not None:<EOL><INDENT>context.update(extra_context)<EOL><DEDENT>context = context.flatten()<EOL>html = template.render(context)<EOL><DEDENT>return html<EOL><DEDENT>
Renders a django-crispy-forms field

:param field: Can be a string or a Layout object like `Row`. If it's a layout
    object, we call its render method, otherwise we instantiate a BoundField
    and render it using default template 'CRISPY_TEMPLATE_PACK/field.html'
    The field is added to a list that the form holds called `rendered_fields`
    to avoid double rendering fields.
:param form: The form/formset to which that field belongs to.
:param form_style: A way to pass style name to the CSS framework used.
:template: Template used for rendering the field.
:layout_object: If passed, it points to the Layout object that is being rendered.
    We use it to store its bound fields in a list called `layout_object.bound_fields`
:attrs: Attributes for the field's widget
:template_pack: Name of the template pack to be used for rendering `field`
:extra_context: Dictionary to be added to context, added variables by the layout object