-1

How do you pass and get results to a python interpreter where the input is coming from a website form?

For instance if you have a web form populated with basic arithmetic expressions like addition, subtraction, multiplication and division.

If you want to pass that expression like 1+1 or 4/6 to the python interpreter and get the result back to show on the web page is that possible? I'm using Django as framework.

Vao Tsun
  • 42,665
  • 8
  • 85
  • 115
cssfan
  • 411
  • 3
  • 5
  • 8

2 Answers2

0

Django is Python. You can write any valid Python code in your view.

Daniel Roseman
  • 567,968
  • 59
  • 825
  • 842
0

You can always use eval() to evaluate an expression.

>>> eval('4*4')
16
>>> 

DANGER Since eval() can execute arbitrary code you should never ever use it with user input. In your case I strongly discourage using it.

In short, there is no very easy way with built-in python functions.

You could try one of the solutions from the answers on this question

Community
  • 1
  • 1
trixn
  • 14,529
  • 1
  • 29
  • 52