On Fri, Aug 24, 2012 at 9:47 AM, Blaxton <blaxx...@yahoo.com> wrote:
> Hi
>
> I am calling a stand alone script from within views.py and
> was able to generate a html file with render_to_string in a stand alone
> script
> by include followng line:
> from django.template.loader import render_to_string

Why would you call an external script instead of importing a module
and calling a function? This seems sub-optimal.

>
> now , need to use "httpresponse" to generate a response.
> is it possible ? tried importing httpresponse and then use
> "return httpresponse" but got error from "return" as it is a stand alone
> script and not a funtion.
>
> currently, I am writing the result of stand alone script to a file and then
> render it
> in views.py.
>
> If I could pass some variables to views.py , or if I could use httpresponse
> in
> stand alone script , then there was no need of writing to a file and then
> render the file.
>
> Thanks for help
>

If there is some really really good reason why you are doing this,
then the standard way to get output from an external script is to have
the script write to stdout, not a file, and have your view function
read the input. Something like this in your view:

import subprocess
content = subprocess.check_output(["python", "/path/to/script", arg1, arg2 ])
return HttpResponse(content)

I still think there is no valid reason to call an external python
script, simply import and call the function you want.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to