Re: Success Message after Submitting a form

2020-04-24 Thread Ahmed Khairy
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(self, form):
>> form.instance.author = self.request.user
>> return super().form_valid(form) 
>>
>>
>> in the HTML 
>>
>> {% if messages %}
>> {% for message in messages %}
>> 
>> {{ message }}
>> 
>> {% 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/3be300cd-16b1-4b2b-8d52-1f4cd95f5015%40googlegroups.com.


Re: Success Message after Submitting a form

2020-04-23 Thread mohamed khaled
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 
>
> {% if messages %}
> {% for message in messages %}
> 
> {{ message }}
> 
> {% 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.


Success Message after Submitting a form

2020-04-23 Thread Ahmed Khairy
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 
   
{% if messages %}
{% for message in messages %}

{{ message }}

{% 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/7ca1c7ad-b38e-4df5-a3c1-93f57219c140%40googlegroups.com.