Initial Values for Form Fields

A snippet showing how to provide initial form values.


# forms.py

from django import forms

class ProfileForm(forms.Form):
    name = forms.CharField(max_length=80)
    newsletter = forms.BooleanField(required=False)
      

# views.py

from django.shortcuts import render
from .forms import ProfileForm

def profile_edit(request):
    initial = {"name": "Jane Doe", "newsletter": True}
    form = ProfileForm(initial=initial)
    return render(request, "profile_edit.html", {"form": form})
      

<!-- templates/profile_edit.html -->

<form method="post" class="bg-white border rounded p-3">
  {% csrf_token %}
  {{ form.as_p }}
  <button type="submit" class="btn btn-primary">Save</button>
</form>

      
Explanation:
  • Pass an initial dict to the form constructor or set initial=... per field.
  • Initial values don't override submitted POST data.
  • Category Forms & Validation
  • Total Views 805
  • Last Modified 04 January, 2026
  • Tags #forms #initial #defaults #input
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.