Why am I getting a NameError when trying to call my Javascript array in a template?-Collection of common programming errors

Here is the view callable for my home page that defines jsdata:

@view_config(route_name='home_page', renderer='templates/edit.pt')
def home_page(request):
    if 'form.submitted' in request.params:
        name= request.params['name']
        input_file=request.POST['stl'].filename
        vertices, normals = [],[]
        for line in input_file:
            ....

        ordering=[]

        ...parsing data...

        data=[vertices,ordering]
        jsdata=json.dumps(data)
        renderer_dict = dict(name=name,data=jsdata)
        ...
        html_string = render('tutorial:templates/view.pt', renderer_dict, request=request)
        with open(filename,'w') as file:
                file.write(html_string)
        return HTTPFound(location=request.static_url('tutorial:pages/%(pagename)s.html')% {'pagename':name}) 

    return {}    

I have imported json as well in that file (views.py). Here it is being rendered on the view.pt template.


var data = ${structure:jsdata};

the NameError points to the jsdata part of that second line. Why is this happening? Doesn’t name error mean that it is undefined? Why is it saying that jsdata is undefined? Should it be passed as a keyword into the render function?

Also: I am aware that there may be errors below that jsdata definition. I have included that part in case it helps you see what I want to be doing with jsdata

  1. renderer_dict = dict(name=name,data=jsdata)
    

    You’re putting it in as data rather than jsdata. Therefore you would want ${structure:data}, or to change the renderer_dict assignment.

Originally posted 2013-11-10 00:15:02.