'Render the field by rendering the passed widget, adding any HTML
attributes passed as attrs. If a widget isn\'t specified, use the
field\'s default widget.'

def as_widget(self, widget=None, attrs=None, only_initial=False):

    if (not widget):
        widget = self.field.widget
    if self.field.localize:
        widget.is_localized = True
    attrs = (attrs or {})
    attrs = self.build_widget_attrs(attrs, widget)
    auto_id = self.auto_id
    if (auto_id and ('id' not in attrs) and ('id' not in widget.attrs)):
        if (not only_initial):
            attrs['id'] = auto_id
        else:
            attrs['id'] = self.html_initial_id
    if (not only_initial):
        name = self.html_name
    else:
        name = self.html_initial_name
    kwargs = {}
    if (func_supports_parameter(widget.render, 'renderer') or func_accepts_kwargs(widget.render)):
        kwargs['renderer'] = self.form.renderer
    else:
        warnings.warn(('Add    the    `renderer`    argument    to    the    render()    method    of    %s.    It    will    be    mandatory    in    Django    2.1.' % widget.__class__), RemovedInDjango21Warning, stacklevel=2)
    return widget.render(name=name, value=self.value(), attrs=attrs, **kwargs)
