I am new to django, i have stuck into an obvious issue which i cant unfold, at the form successful submission i have, put a message on the main home page where the user will be redirect to, the issue is its not returning the message.see below view:
def service(request):
form = GetStartedForm(request.POST or None)
if form.is_valid():
form.save()
x = messages.success(request, 'We have recorded your request and we will contact you soon!')
print(x)
print('Form Successfull!')
return HttpResponseRedirect(reverse_lazy('home'))
context = {'form': form}
return render(request, 'bluetec/service.html', context)
form:
class GetStartedForm(forms.ModelForm):
class Meta:
model = GetStarted
fields = '__all__'
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['name'].widget.attrs.update({'size': 5, 'class': 'form-control', 'placeholder': 'Enter your name:'})
self.fields['phone_no'].widget.attrs.update({'size': 5, 'title': 'Phone No', 'class': 'form-control', 'placeholder': 'Enter your phone no:'})
self.fields['email'].widget.attrs.update({'size': 10, 'title': 'Email', 'class': 'form-control', 'placeholder': 'Enter your email:'})
self.fields['description'].widget.attrs.update({'size': 10, 'title': 'description', 'class': 'form-control', 'placeholder': 'Enter your projects description:'})
and the html is
<body>
<div id="wrapper" >
{% include 'bluetec/messages.html' %}
<!-- header begin -->
<header class="{% block class %} header-light transparent scroll-light {% endblock class %}">
<div class="container">
<div class="row">
the messages.html file is
{% if messsages %}
{% for message in messages %}
<div class="alert alert-{{ message.tags }}" id="msg" role="alert">
{{ message }}
</div>
{% endfor %}
{% endif %}
when i print the x value to see whats its returning, its returning 'None' and 'form Successfull' i tried many answers not none points to my issue. idk what the issue is any help would be appreciated,