views:

45

answers:

2
$('#upload').click(function(){
        $('#main .right').html("{% extends 'a.html' %}")
    })

but this is error ,

how to make this code running .

thanks

+2  A: 

Let me guess -- your element ends up containing "{% extends 'a.html' %}"? If so, it's because your js file is not being parsed by the template engine. In any case, you might be better served by making this an AJAX request, like the following:

$('#upload').click(function() {
    $.get("a.html", function(data) {
        $('#main .right').html(data);
    });
});

If you're feeling unusually fancy, you can add some animation to let the user know that a request is pending.

Faisal
A: 
$('#upload').click(function(){
    $('#main .right').html("{% extends 'a.html' %}")
})

Do you mean {% include %}? I can't see what purpose putting an extends inside a script block would serve.

If you're actually templating into that {% ... %} block successfully, then you're including a load of HTML content. HTML content usually has lots of newlines and " characters in it, both of which will immediately terminate the JavaScript string literal inside the html() call and cause a big old syntax error. (Other characters that will cause trouble include \ and </.)

If you wanted this to work, you'd need to take the output of the a.html template and encode it using JavaScript string literal rules. For a normal string this would be done using the escapejs filter in Django or the json library in general. However I don't think there's any way to do filtering on the output of an {% include %} command.

How about including the HTML in a hidden part of the document and showing/hiding it from script?

bobince