Printing Output to Browser Problem

10 views
Skip to first unread message

Jason Head

unread,
Jan 29, 2014, 12:23:47 AM1/29/14
to django...@googlegroups.com
I'm trying to get output from NLTK to print to the browser, but can't seem to get the output there.
I have tested the core function in the Python shell, so I know that works.

Any ideas on how to get the output printed out?
The routing seems to work fine, and am pretty sure things work until the last call.

Here's the function from Django's views.py:
def concordance(request):
    script = request.GET.get('script')
    textPath = '[path to dir]'
    fullTextPath = textPath+script+'.txt'
    
    f=open(fullTextPath)
    raw=f.read()
    
    tokens = nltk.word_tokenize(raw)
    text = nltk.Text(tokens)
    
    result = text.concordance('love')
    
    return HttpResponse(result, content_type="text/html")
Reply all
Reply to author
Forward
0 new messages