Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 613647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:01:32+00:00 2026-05-13T18:01:32+00:00

I have a form with an email property. When using {{ form.email }} in

  • 0

I have a form with an email property.

When using {{ form.email }} in case of some validation error, Django still renders the previous value in the input tag’s value attribute:

<input type="text" id="id_email" maxlength="75" class="required"
       value="some@email.com" name="email">

I want to render the input tag myself (to add some JavaScript code and an error class in case of an error). For example this is my template instead of {{ form.email }}:

<input type="text" autocomplete="on" id="id_email" name="email"
       class="email {% if form.email.errors %} error {% endif %}">

However, this does not display the erroneous value (some@email.com in this example) to the user.

How do I get the field’s value in the template?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:01:33+00:00Added an answer on May 13, 2026 at 6:01 pm

    The solution proposed by Jens is correct.
    However, it turns out that if you initialize your ModelForm with an instance (example below) django will not populate the data:

    def your_view(request):   
        if request.method == 'POST':
            form = UserDetailsForm(request.POST)
            if form.is_valid():
              # some code here   
            else:
              form = UserDetailsForm(instance=request.user)
    

    So, I made my own ModelForm base class that populates the initial data:

    from django import forms 
    class BaseModelForm(forms.ModelForm):
        """
        Subclass of `forms.ModelForm` that makes sure the initial values
        are present in the form data, so you don't have to send all old values
        for the form to actually validate.
        """
        def merge_from_initial(self):
            filt = lambda v: v not in self.data.keys()
            for field in filter(filt, getattr(self.Meta, 'fields', ())):
                self.data[field] = self.initial.get(field, None)
    

    Then, the simple view example looks like this:

    def your_view(request):   if request.method == 'POST':
        form = UserDetailsForm(request.POST)
        if form.is_valid():
          # some code here   
        else:
          form = UserDetailsForm(instance=request.user)
          form.merge_from_initial()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a contact form sending itself to me by email using ASP classic,
Using simple_form , I have a simple input like this: <%= f.input :email %>
I have a form for logging: val loginForm = Form(tuple( email -> (nonEmptyText verifying
I have a Rails form for email, and I would like to have auto-completion
I have a form with a name and an email address. I want a
I have a contact form where the email is actually accessible in the source,
I have a form that validates the email address and I want to be
I have a form in which i have a text box for email and
I have a form, that has about 10 text entries (user, address, email etc;)
I have an email attachment form that is working fine when the <form action=processingtheformfile.php>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.