On Tue, Nov 12, 2013 at 9:35 AM, info rekal <i...@rekal-media.com> wrote: > Hello, > > We are running Django 1.5.1 with some ajax on the front end > (http://goo.gl/RuofnO) that allows visitors to add certain pages to their > favorites list (similar in functionality to a shopping cart). The 'Save to > Favorites' does not seem to function correctly when the cache middleware's > are enabled: > > 'django.middleware.cache.UpdateCacheMiddleware', > 'django.middleware.cache.FetchFromCacheMiddleware', > > If I leave the above middleware's disabled, the ajax 'Save to Favorites" > works successfully; > > However when caching middlewares are enabled, it may allow you to add one > property to the list, but after you will still get 'Favorite Added' message > upon clicking 'Save to Favorites' but upon viewing the list you find nothing > was added to the list. > > I tried applying never cache to the view responsible for the ajax response > in attempt exclude this part > of the page from cache, but this did not seem to help any.
never_cache is a view decorator. This is not a view - views return HttpResponse subclasses. > >> #from django.views.decorators.cache import never_cache >> >> >> >> #@never_cache >> def build_favorites(session_favorites): >> listing = ListingAPI() >> favorites = [] >> for prop_type, _id, beds in session_favorites: >> if prop_type == 'robo': >> obj = Property.objects.get(id=_id) >> if beds == '1': >> price = obj.one_bed_price >> elif beds == '2': >> price = obj.two_bed_price >> elif beds == '3': >> price = obj.three_bed_price >> else: >> obj = listing.get(_id).get('listing', {}) >> price = obj.get('price','USD') >> >> favorites.append((prop_type, obj, beds, price)) >> >> return favorites > > > > Does anyone have any ideas on why the 'Save to Favorites' functionality > breaks when caching is enabled? Check the javascript that submits this request. I'm guessing you are submitting a GET request that is not idempotent - that is, it changes the database. Submit it as a POST request, submit arguments to the request in the POST arguments, not as part of the URL. Cheers Tom -- 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 post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1JpgYR8JY5_08nJ9ANs9cc_JMjsAN4PuGtW5AoJ%3DP7Pgg%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.