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

  • SEARCH
  • Home
  • 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 7015755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:41:37+00:00 2026-05-27T22:41:37+00:00

I can’t figure out why validation doesn’t work in my app. My problem is

  • 0

I can’t figure out why validation doesn’t work in my app.

My problem is that every time I send the form in my template (base_contact.html), the app sends me to the /Thanks/ view, but it’s so weird, because it does even if the form in the template is empty or has several validation errors. So I think that form.is_valid() is not working properly in this case. These are my files:

models.py

from django.db import models
from django import forms

class ContactForm(forms.Form):
    subject = forms.CharField(max_length=100)
    message = forms.CharField(widget=forms.Textarea())
    sender = forms.EmailField()
    cc_myself = forms.BooleanField(required=False)

views.py

from django.shortcuts import render_to_response
from django.core.context_processors import csrf
from django.http import HttpResponseRedirect
from main.models import ContactForm
from django.core.mail import send_mail

def contact(request):
if request.method == 'POST': # If the form has been submitted...
    form = ContactForm(request.POST) # A form bound to the POST data
    if form.is_valid(): # All validation rules pass
        # Process the data in form.cleaned_data
        subject = form.cleaned_data['subject']
        message = form.cleaned_data['message']
        sender = form.cleaned_data['sender']
        cc_myself = form.cleaned_data['cc_myself']
        recipients = ['example@gmail.com']

        send_mail(subject, message, sender, recipients)
        return HttpResponseRedirect('/Thanks/') # Redirect after POST
else:
    form = ContactForm() # An unbound form
return render_to_response('base_contact.html', {'form': form})

base_contact.html

<div class="forms">
<table>
<form action="/Contact/" method="post">{% csrf_token %}
    <tr><th><label for="id_sender">Your email:</label></th>
        <td><input class="text" type="text" name="sender" id="id_sender" /></td></tr>
    <tr><th><label for="id_subject">Subject:</label></th>
        <td><input class="text" id="id_subject" type="text" name="subject" maxlength="100" /></td></tr>
    <tr><th><label for="id_message">Message:</label></th>
        <td><textarea class="styletextarea" name="message" id="id_message" rows="7" cols="35" /></textarea></td></tr>
    <tr><td></td><td><input class="button" type="submit" value="Send" /></td></tr>
</form>
</table>
</div>

Thanks for your help 🙂

  • 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-27T22:41:38+00:00Added an answer on May 27, 2026 at 10:41 pm

    Check the indentation of the following line

    return HttpResponseRedirect('/Thanks/')
    

    In Python (and therefore Django), indentation is very important. It is recommended to use 4 spaces per indentation level. Avoid using tabs. You can often change the settings for your text editor or ide to use 4 spaces when you press the tab key.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me trying to find out why this doesn't work. The brushes
Can a LINQ enabled app run on a machine that only has the .NET
can anyone tell me why this doesn't work? db = openOrCreateDatabase(database.db, SQLiteDatabase.CREATE_IF_NECESSARY, null); db.setLocale(Locale.getDefault());
Can't work out a way to make an array of buttons in android. This
Can't figure out how to do this in a pretty way : I have
Can somebody point me to a resource that explains how to go about having
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Can I call select before recv_from on a socket that is blocking?
Can I have a project that has some parts written in c and other
Can some one confirm me that only one UIWindow instance is possible in any

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.