@ajax_request
def json_images(request, dir_name):
    path = os.path.join(settings.MEDIA_ROOT, dir_name)
images = []
for f in os.listdir(path):
    if f.endswith('jpg') or f.endswith('png'):
        images.append('%s%s/%s' % (settings.MEDIA_URL, dir_name, f))
return {'images': images}
Django: Auto-generating a list of files in a directory