Tuesday, January 28, 2014

Printing Output to Browser Problem

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")

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/03db20c5-c266-43b1-854a-b2303c933850%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment