Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8343749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:09:38+00:00 2026-06-09T06:09:38+00:00

here is my django view @csrf_exempt @login_required def get_playlists_for_user(request): gets all playlists for user

  • 0

here is my django view

@csrf_exempt
@login_required
def get_playlists_for_user(request):
    """
    gets all playlists for user
    """
    logging.info('getting playlist for user - ' + str(request.user))
    playlists = UserPlaylist.objects.get_all_playlists_for_user(request.user)
    logging.info('user=%s, playlists=%s'%(request.user, playlists))
    return HttpResponse(playlists)

Here is how jQuery calls it via ajax

$.ajax({
        url: '/getUserPlaylists',
        success: function(response, textStatus, jqXHR){

            console.log(response);
        },
        error: function(response, textStatus, jqXHR) {

        }
});

the view return the list of Playlist objects

playlists=[<Playlist id:1, name:first, date_created:2012-08-05 06:28:31.954623+00:00, deleted:False>, <Playlist id:2, name:my, date_created:2012-08-06 12:47:13.023537+00:00, deleted:False>, <Playlist id:3, name:new, date_created:2012-08-06 12:48:45.708277+00:00, deleted:False>, <Playlist id:5, name:second, date_created:2012-08-06 21:19:33.050187+00:00, deleted:False>]

The schema model for Playlist is

class Playlist(models.Model):
    name = models.CharField(max_length=30)
    date_created = models.DateTimeField(auto_now_add=True)
    date_modified = models.DateTimeField(auto_now=True)
    deleted = models.BooleanField(default=False)

When I log them in firebug I see them as

Playlist objectPlaylist objectPlaylist objectPlaylist object

How can I read these objects in jQuery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:09:40+00:00Added an answer on June 9, 2026 at 6:09 am

    You need to return the Python objects in a form javascript can understand which is usually json (javascript object notation). So in your view, convert your django queryset into json, using django’s serialisers:

    from django.core import serializers
    ...
    json = serializers.serialize('json', playlists)
    return HttpResponse(json, mimetype="application/json")
    

    and in your ajax:

    $.ajax({
           url: '/getUserPlaylists',
           dataType: "json",
           success: function(response, textStatus, jqXHR){
               for(var i = 0; i < response.length; i++ ){
                   var playlist = response[i]['fields'];
                   // Do something now with your playlist object
                   console.log(playlist.name);
               }
           },
           error: function(response, textStatus, jqXHR) {
           }
    });
    

    this will mean the response in your ajax success will be something like this (a list of javascript objects) :

    [{ "model" : "playlist.Playlist", "pk" : 1, "fields" : { "name" : "...", ... } }]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Getting started with Django 1.3 here. Loving the system so far, but struggling on
Here's the view.py. show_checkout is called and runs all the way to return HttpResponseRedirect('/receipt/')
In my Django project I am using Product.objects.all().order_by('order') in a view, but it doesn't
This is defined in my settings.py TEMPLATE_CONTEXT_PROCESSOR = ( django.core.context_processors.request, # <- HERE django.contrib.auth.context_processors.auth,
Here in my django ModelAdmin I want to filter foreignkey choices based on current
Here is a Django model I'm using. class Person(models.Model): surname = models.CharField(max_length=255, null=True, blank=True)
I am following the django tutorial here . I have copied everything exactly. After
Here's part of my Django app's models.py : class Person(models.Model): birth_year = WideYear(null=True, blank=True)
here is my code: urls.py: from django.conf.urls import patterns from views import show,showpage urlpatterns
Here is a part of my html code (video urls marked with a django-template

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.