[Answered ]-Can't send an email in Django 1.9

1👍

As the Django doc mentioned,

Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL.

The call of /contact/auth/ first matched by /contact, and you did not offer the post function in your ContactView, that’s why you got 405. So there are two way to fix this:

1

Simply change /contact/auth/ to /contact123/auth/(note the trailing slash).

I recommend you write like this:

url(r'^contact123/auth/', views.send_email, name='post_url'),

and this:

<form action="{% url 'post_url' %}" method="post">
...

This will make the change of you url pattern much more easier.

2.

Add the trailing $ like this url(r'^contact/$', views.ContactView.as_view(), name='contact'),.

Either two way worked fine as I tested.

1👍

The issue is in the patterns. You are calling contact/auth which is not matching the pattern url(r'^contact/auth/', views.send_email), because of the trailing slash. You must use contact/auth/. Also just for info all post calls must have a trailing slash. That’s why the 405 response is getting returned.

Leave a comment