Skip to content

Instantly share code, notes, and snippets.

@rg3915
Created March 17, 2018 01:39
Show Gist options
  • Save rg3915/f0cb92e1ac8a707bba8e1a881fb4c09f to your computer and use it in GitHub Desktop.
Save rg3915/f0cb92e1ac8a707bba8e1a881fb4c09f to your computer and use it in GitHub Desktop.
Form render with widget_tweaks and required fields
<!-- https://djangosnippets.org/snippets/474/ -->
{% load widget_tweaks %}
<style>
span.required:after {
content: "*";
color: red;
}
</style>
{% for field in form.visible_fields %}
<div class="form-group{% if field.errors %} has-error {% endif %}">
<label for="{{ field.id_for_label }}">
{% if field.field.required %}
<span class="required">{{ field.label }} </span>
{% else %}
{{ field.label }}
{% endif %}
</label>
{% render_field field class="form-control" %}
{% for error in field.errors %}
<span class="text-muted">{{ error }}</span>
{% endfor %}
</div>
{% endfor %}
@rg3915
Copy link
Author

rg3915 commented Feb 15, 2020

label.required:after {
      content: '*';
      color: red;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment