Skip to content

Instantly share code, notes, and snippets.

@alorence
Created January 19, 2026 20:55
Show Gist options
  • Select an option

  • Save alorence/3df63427d7b2187a7b0cedf2053a731f to your computer and use it in GitHub Desktop.

Select an option

Save alorence/3df63427d7b2187a7b0cedf2053a731f to your computer and use it in GitHub Desktop.
"""
Prevent Django form to automatically append colon ':' after labels when rendering forms
"""
class NoColonSuffixFormMixin:
"""
Prevent ':' suffix to be added on fields labels
Usage:
class MyForm(NoColonSuffixFormMixin, forms.Form):
pass
"""
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
self.label_suffix = ""
class NoColonSuffixFormViewMixin:
"""
Prevent ':' suffix to be added on fields labels, on form displayed via a CBV FormView.
Usage:
class MyFormView(NoColonSuffixFormViewMixin, FormView):
form_class = MyForm
"""
def get_form_kwargs(self, *args: Any, **kwargs: Any) -> dict[str, Any]:
kwargs = super().get_form_kwargs(*args, **kwargs)
# When unset, form.label_form take ':' as default value
kwargs["label_suffix"] = ""
return kwargs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment