-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
  • 47,234
  • 13
  • 100
  • 132
cssfan
  • 421
  • 3
  • 5
  • 8

2 Answers2

0

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

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
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
  • 15,761
  • 2
  • 38
  • 55