Hello Members, I am creating a simple django forms and integrating it with models. I have followed the django docs to perform the task, but I believe that I am doing some mistake due to which I am getting "ValueError at /blog/contact/". Below is the full error stack: Environment:
Request Method: GET Request URL: http://localhost:8000/blog/contact/ Django Version: 2.2.5 Python Version: 3.6.8 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'BLOG'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'] Traceback: File "/root/PycharmProjects/myvenv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner 34. response = get_response(request) File "/root/PycharmProjects/myvenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 126. "returned None instead." % (callback.__module__, view_name) Exception Type: ValueError at /blog/contact/ Exception Value: The view BLOG.views.contact didn't return an HttpResponse object. It returned None instead.Below are my python files snippet: models.py-------------from django.db import models class Contact(models.Model): name = models.CharField(max_length=100) email = models.EmailField(max_length=200) phone = models.IntegerField() Comment = models.TextField(blank=False) def __str__(self): return self.emailforms.pyfrom django import forms from .models import Contact class ContactForm(forms.ModelForm): name = forms.CharField(label='Your name', max_length=100) email = forms.EmailField(label='Your Email Address', max_length=200) phone = forms.IntegerField(label='Your Phone Number', max_value=20) Comment = forms.TextInput() class Meta: model = Contact fields = ('name', 'email', 'phone', 'Comment')views.pyfrom django.http import HttpResponse from django.shortcuts import render, redirect from .forms import ContactForm def contact(request): if request.method == 'POST': name_r = request.POST.get('name') email_r = request.POST.get('email') phone_r = request.POST.get('phone') comment_r = request.POST.get('comment') form = ContactForm(name=name_r, email=email_r, phone=phone_r, comment=comment_r) if form.is_valid(): form.save() form = ContactForm() return HttpResponse('Thank you for your enquiry') return redirect(request, 'contact.html') else: form = ContactForm() return render(request, 'contact.html', {'form': form})Any suggestions.... Regards, AS -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1654382225.2288963.1573500974885%40mail.yahoo.com.

