0

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" 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>

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Which action do i put? Like action="What in here"
The URL leading to your send_email view.
Wdym, there is no url that goes to send_email
After you hit the "Submit" button your browser sends POST request to the URL for action. So if you want this request to be processed with your view send_email, you have to configure URL for your view in urls.py.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.