First time here? Check out the FAQ!

Ask Your Question
2

Implementing Sage on Website

asked 13 years ago

anonymous user

Anonymous

updated 13 years ago

Shashank gravatar image

Here is what I would like to do; please let me know what might be the best way/programs to use to do it:

*Write Python code, involving Sage commands/functions

*Have a website where user input is taken, and the code is run

*The output of the Python code is not to be displayed exactly; rather, the output of the Python code will be code of a TeX source file.

*The website should then display the output of that TeX source (either as an image or pdf, but in the webpage -- not something to be downloaded by the user).

Any help greatly appreciated (specifically with the best way to implement the code in the website, and also if anyone knows a good way to do the 4th *)!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 13 years ago

Shashank gravatar image

Ok it is a bit late but I to look around the web a bit and here is what I found. If you have a web hosting server then you will have access to a directory called cgi-bin and public_html. In public_html keep the following file named test.html

<html><body>
<form method="get" action="./cgi-bin/test.cgi">
Input: <input type="text" name="name">
<input type="submit" value="Submit">
</form>
</body></html>

Now my cgi-bin is a subdirectory of public_html but change the path to whatever you have on your server. In cgi-bin keep a file test.cgi. The contents of test.cgi are as follows. You can import sage in the following script and use sage commands.

#!/usr/bin/python
print "Content-Type: text/plain\n\n"
import cgi
form = cgi.FieldStorage() # instantiate only once!
name = form.getfirst('name', 'empty')
ans=eval(name)
name = cgi.escape(name)
print """\
Content-Type: text/html\n
<html><body>
<p>Answer is "%s"</p>
</body></html>
""" % ans

Here the output is in html format but you can change it to make TeX. Input

image description

Output

image description

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 13 years ago

Seen: 564 times

Last updated: Feb 21 '12