Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to send mail using django

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, ["aleksalav123@gmail.com"])
        return HttpResponseRedirect("dashboard/")

HTML:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading