0

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.

<script>
var data = ${structure:jsdata};
</script>

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

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
BigBoy1337
  • 4,735
  • 16
  • 70
  • 138
  • Can you 1) fix your indentation, 2) post the actual traceback? – mgilson Feb 12 '13 at 17:22
  • 1) whats wrong with the indentation and 2) if by traceback you mean full error statement, I apologize but i am away from my computer right now. I can post it in a few hours – BigBoy1337 Feb 12 '13 at 17:54
  • It looks like the indentation was fixed for you by @MartijnPieters. Your decorator wasn't aligned with the function properly -- I wasn't sure if that was the only problem. So I suppose now you could read that as "1) Check your indentation to make sure Martijn got it right" ;-). And yes, the full error statement is what I meant by 2). :-) – mgilson Feb 12 '13 at 17:58

1 Answers1

2
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.

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215