why i can't alert this string which is return from django render_to_response

By : zjm1126
Source: Stackoverflow.com

django code:

return render_to_response(template_name, {
        "form": form,
    }, context_instance=RequestContext(request))

and html:

<script type="text/javascript">
        var a='{{form}}'


it's error is 'unterminated string literal',

and i see this in firebug :

<script type="text/javascript">
        var a='"<tr><th><label for="id_username">Username:</label></th><td><input id="id_username" type="text" class="textinput" name="username" maxlength="30" /></td></tr><tr><th><label for="id_email">Email (optional):</label></th><td><input id="id_email" type="text" class="textinput" name="email" /></td></tr>"';

how do i alert the 'form' string .


By : zjm1126


I am unable to reproduce this error, pasting the above into a javascript console works without problems. Is it possible that there is something else done with a? Is above a simplification or exact javascript? Maybe you can show the entire HTML?

By : kb.

Maybe try putting in semi-colons at the ends of the lines in your Django template file?

<script type="text/javascript">
    var a='{{form}}';


Odd though, I

Check the HTML source of the page using "View source" rather than Firebug. I predict your {{form}} value has a line break in it, which will cause the error you're seeing.

By : Tim Down

This video can help you solving your question :)
By: admin