0

In my django oscar project i have a wishlist templte which contains button to delete product from wishlist. The product is getting deleted after ajax call but the success message which is created in deleteview is loading after refreshing page.

Optimus
  • 1
  • 3
  • Oscar itself doesn't use ajax to manage wishlists - so I'm guessing you have implemented this yourself? If so, you also need to implement handling of messages, otherwise they will, as you note, be rendered on the next full page load. Your options are (a) to override the view and disable use of the Django messages framework or (b) include in your ajax response any messages that are stored in the session. – solarissmoke Aug 06 '19 at 03:11
  • @solarissmoke Im not sure how to include messages in ajax response because im using a seperate html for messages which is included in main page. – Optimus Aug 07 '19 at 05:54

1 Answers1

0

in views.py, return

response = {
    'msg': render_to_string(
        'messages/wishlist-msg.html',
        {
            'message': msg,
        },
    ),
}
return HttpResponse(
    json.dumps(response),
    content_type='application/json',
)

wishlist-msg.html

  <div class="message-notification">
 {{ message }}
  </div>

when ajax success, js file

const $message = $('.message-notification');
# code for ajax

    done(function (data) {
         message.append(data['msg']);
          });