'the contact form dont send me it is show 404
I am a beginner in django and I have had a problem for 1 week now, several tutorials that I have watched have not solved anything, so I trust you.
it's just making the different contact forms of my website designed with django work I therefore attach the source code of my project and the code, when I launch the send button (submit) I receive a 404 error
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_FORM_EMAIL="[email protected]"
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = '587'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'Gedeon225@@'
EMAIL_USE_TLS = 'True'
EMAIL_USE_SSL = 'False'
def send_mail(request):
if request.method=="POST":
name = request.POST.get['name']
subject = request.POST.get['subject']
email = request.POST.get['email_address']
message = request.POST.get['message']
send_mail(
name,
subject,
email,
message,
'[email protected]',
['[email protected]'],
fail_silently=False,
)
message.info (request, 'Votre message a été envoyé')
return render(request, 'contact.html')
path('send_mail/', views.send_mail, name="send_mail"),
<form action="send_mail" method="POST">
{% csrf_token %}
<div class="form-control-wrap">
<div id="message" class="alert alert-danger alert-dismissible fade"></div>
<div class="form-group">
<input type="text" class="form-control" id="fname" placeholder="Nom et prénom" name="fname">
</div>
<div class="form-group">
<input type="text" class="form-control" id="subject" placeholder="Le sujet" name="subject">
</div>
<div class="form-group">
<input type="email" class="form-control" id="email_address" placeholder="E-mail" name="email">
</div>
<div class="form-group">
<textarea class="form-control" rows="8" name="message" id="message" placeholder="message"></textarea>
</div>
<div class="form-group">
<button type="submit" class="btn v8" >Envoyer le message</button>
</div>
</div>
</form>
Solution 1:[1]
The action attribute of your form is incorrect. Either leave it empty (if you're posting to the same view), or use the url template tag to generate the correct URL:
<form action="{% url 'send_mail' %}" method="POST">
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | solarissmoke |
