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 776641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:28:53+00:00 2026-05-14T19:28:53+00:00

In some of the code I’m working on, the author max AJAX calls to

  • 0

In some of the code I’m working on, the author max AJAX calls to a Django view that returns JSON.

Once the JSON is retrieved, it’ll be injected into the page with a function that looks like this (note, this is a simplification, but I’m sure you know what I’m getting at here):

function build_event_listing(events) {
    var html = '';

    for(int i = 0; i < events.length; i++) {
        event = events[i];

        html += "<h2>" + event.title + "</h2>\n";
        html += "<p>" + event.description + "</p>";
        html += "Click <a href='/event/view/" + event.id + "'>here<a> for more info.";

    }

    events_div.html(html);
}

I really don’t like this approach. To change the look of each event listing, the designer would have to modify that ugly JS. I’d much rather make use of Django’s templating system, but I’m wondering how I can do this?

I had the idea of writing the view like this:

def view_listings(req):
    events = models.Event.objects.all()

    html = []
    for event in events:
        html.append(
            render_to_string('event/single_event.html', {
                'event': event,
            }, context_instance=RequestContext(req))

    return HttpResponse(''.join(html), mimetype='text/html')

… but it just seems like there should be a better way.

Any ideas?

  • 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-05-14T19:28:53+00:00Added an answer on May 14, 2026 at 7:28 pm

    I wrote a Django/Ajax library that organises this for you. You write your template as such:

    {% load ajax %}
    {% adjax_include "event/_event_list.html" %}
    

    In your view you would do something like:

    import adjax
    
    @adjax_response
    def view_listings(req):
        events = models.Event.objects.all()
        adjax.render_to_response("event/_event_list.html", {'events': events})
    

    There is also a template tag that flags a single value for replacement, eg {% adjax event.title %} and then adjax.update(request, event, ('title', 'description', 'id'))
    in the view. But this is only single objects currently, not query sets. It’s a good idea though, I might quickly implement it.

    See http://adjax.hardysoftware.com.au/how/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some code that I don't have control over is overriding the global JSON object
Consider some code that calls, say, file = new RandomAccessFile(x, r); file.getChannel().map(....) and wants
In some code I'm working on I have noticed that several variables are being
Some code I am working with replaces some HTML elements that have Dojo event
Got some code here that isn't working: $(#sidebar ul li:last).each(function(){ $(this).addClass(last); }); Basically I
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
Some code a production server which uploaded files has seemingly stopped working with the
first some code: I have many elements like that: <section class=item> <div class=caption> </div>
In some code I'm working on I should take care of ten independent parameters
Some code I am working on uses COleDataSource::CacheGlobalData , passing as CF_TEXT an HGLOBAL

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.