Home > Software design >  How to send mail using django
How to send mail using django

Time:01-09

So im trying to send a gmail in my django project. But every time i press the submit button i get html 405 error page.

Views:

def send_email(request):
    if request.method == "POST":
        name = request.POST.get("name")
        email = request.POST.get("email")
        message = request.POST.get("message")
        send_mail(name, email, message, ["[email protected]"])
        return HttpResponseRedirect("dashboard/")

HTML:

<form action="" method="POST">
    {% csrf_token %}
    <input type="text"  name="message_name" placeholder="Full name" id="full_name">
    <input type="text"  name="message_email" placeholder="Email" id="login-email">
    <input type="text"  name="message" placeholder="Poruka" id="text">
    <input type="submit" value="Pošalji" >
</form>

CodePudding user response:

You forget to put actual URL to the action of the form. Then you send POST request to your current URL (which seems to not handle POST requests) and you justly receive 405 Method Not Allowed error.

  •  Tags:  
  • Related