just use SuccessMessageMixin

from django.contrib.messages.views import SuccessMessageMixin

class PostCreateView(LoginRequiredMixin,SuccessMessageMixin, CreateView):
    model = Post
    fields = ['caption', 'design']
    template_name = "post_form.html"
    success_url = '/score'
    success_message = "Your Design has been submitted for Review"



it will work 

On Friday, 24 April 2020 03:24:56 UTC+2, Ahmed Khairy wrote:
>
> I have created this class with the success message but I am not receiving 
> the success message I requested, other pages are showing them but this one 
> is not 
>
> What might be wrong? 
> In the views: 
> class PostCreateView(LoginRequiredMixin, CreateView):
>     model = Post
>     fields = ['caption', 'design']
>     template_name = "post_form.html"
>     success_url = '/score'
>     success_message = "Your Design has been submitted for Review"
>
>     def form_valid(self, form):
>         form.instance.author = self.request.user
>         return super().form_valid(form) 
>
>
> in the HTML 
>    <!-- Navbar -->
>         {% if messages %}
>             {% for message in messages %}
>                 <div class="alert alert-{{ message.tags }}" style="
> padding-top:80px">
>                     {{ message }}
>                 </div>
>             {% endfor %}
>         {% endif  %}
>
>
>
> Thank you 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/196d26db-0876-4b01-92b0-12686cfad066%40googlegroups.com.

Reply via email to