Answer the question
In order to leave comments, you need to log in
Where to convert an error into a text message?
The model has a method that processes the sent data and returns an error if something happens.
Where is the best place in the framework to translate the error code into a message for the user?
View or template?
Answer the question
In order to leave comments, you need to log in
views.py
from django.contrib import messages
def feedback(request):
form = FeedbackForm(request.POST or None)
if form.is_valid():
instance = form.save(commit=False)
instance.save()
messages.success(request, 'Ваше сообщение отправлено! Мы свяжемвся с Вами в скором времени!')
return render(request, "feedback.html")
context = {
'form': form,
}
return render(request, 'feedback.html', context)
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question