I am creating a project to send emails, however I am doing some tests and I came across the following problem:
The view send_mail.core.views.index did not return an HttpResponse object. It returned None instead.
Below are my lines of code:
#views
from django.shortcuts import render, render_to_response
from django.template.context import RequestContext
from .forms import SendMail
def index(request):
if request.method == "POST":
form = SendMail(request.POST)
if form.is_valid():
subject = form.cleaned_data['subject']
print(form)
return render_to_response('index.html',
context_instance=RequestContext(request, {"form": form},))
else:
print("ops!!")
#forms
from django import forms
class SendMail(forms.ModelForm):
subject = forms.CharField(max_length=80)
#template
<!DOCTYPE html>
<html>
<head>
<title>some title</title>
</head>
<body>
<form action="." method="POST">
{% csrf_token %}
{{form.as_p}}
</form>
</body>
</html>
I do not need to save the data in a database, so I'm not using a model, I just need it, what I write inside the textarea
field is printed. In future I want to send emails with the same, the intention is to create an email sender, where it will contain a field with the client's email and a textarea
with the desired subject.
Can anyone tell me why the above error?