Friday, April 24, 2020

Re: Success Message after Submitting a form

Thank you Ramadan Kareem

On Friday, April 24, 2020 at 12:11:09 AM UTC-4, mohamed khaled wrote:
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(selfform):
        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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3be300cd-16b1-4b2b-8d52-1f4cd95f5015%40googlegroups.com.

No comments:

Post a Comment