<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_field_template(self, bound_field, template_name=None):
 """ Returns the field template to use when rendering a form field to HTML. Preference of template selection: 1. Provided method argument `template_name` 2. Template from `field_template_overrides` selected by field name 3. Template from `field_template_overrides` selected by field class 4. Form class property `field_template` 5. Globally defined default template from `defaults.LAYOUT_FIELD_TEMPLATE` :param bound_field: `BoundField` instance to select a template for. :param template_name: Optional template to use instead of other configurations. :return: Template name to use when rendering the form field. """

        if template_name:
            return template_name

        templates = self.field_template_overrides or {}

        template_name = templates.get(bound_field.name, None)
        if template_name:
            return template_name

        template_name = templates.get(bound_field.field.__class__, None)
        if template_name:
            return template_name

        if self.field_template:
            return self.field_template

        return defaults.FIELD_DEFAULT_TEMPLATE