These are chat archives for django/django

11th
Jun 2018
kashyap_py_dev
@Neerajkashyap
Jun 11 2018 06:25
@PabloLefort i am not using any cms. just looking for some other option instead of using cms. if there is any page builder for django.
:]
@elcolie
Jun 11 2018 09:19
@DErekXx Can you give the simplify version of your code to online repository?
Luke-VideoLibre
@LukeVideo
Jun 11 2018 09:25
Hy i'm using django 2.0, i'm struggling with messages. I just want a simple confirmation
I've got this Createcontact form
class CreateContact(generic.FormView):
    model = ContactForm
    form_class = Contact
    success_url = reverse_lazy('')
    template_name = 'contact/contact_form.html'

    def form_valid(self, form):
        messages.add_message(
            request, messages.success, "Votre message a bien été envoyé.")
        return super(CreateContact, self).form_valid(form)
and in my template
                <div class="valid">
                  {% if messages %}
                  <ul class="messages">
                      {% for message in messages %}
                      <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
                      {% endfor %}
                  </ul>
                  {% endif %}
                </div>
but nothing appears. I must of skipped a step but i can't figure what.
Lefort
@PabloLefort
Jun 11 2018 12:08
@Neerajkashyap take a look https://wagtail.io/
@LukeVideo you have 'django.contrib.messages.middleware.MessageMiddleware', on your settings?
Luke-VideoLibre
@LukeVideo
Jun 11 2018 12:15
@PabloLefort Yes and 'django.contrib.sessions.middleware.SessionMiddleware',
Lefort
@PabloLefort
Jun 11 2018 12:17
and 'django.contrib.messages' is in INSTALLED_APPS ?
Luke-VideoLibre
@LukeVideo
Jun 11 2018 12:18
Yes.
Lefort
@PabloLefort
Jun 11 2018 12:23
can you show the output of:
response = super(CreateContact, self).form_valid(form)
print(type(response))
Luke-VideoLibre
@LukeVideo
Jun 11 2018 13:10
Where would you put that ?
I tried at the end of te class but doesn't seem to work..
Lefort
@PabloLefort
Jun 11 2018 13:42
    def form_valid(self, form):
        messages.add_message(
            request, messages.success, "Votre message a bien été envoyé.")
        response = super(CreateContact, self).form_valid(form)
        print(type(response))
        return response