I am making a web server using webpy and right now I have a simple form and a special class I wrote. I want the user to be able to write in code to the form and if the input is a function call, to call the function the user submitted, else do anything with the input if it’s not a function call. I believe this would have to be achieved somewhere in the template file? any help would be appreciate
Share
If I understand correctly, you’re looking for a way to run client-submitted code on the server, getting input from a form.
So assuming you have a form template that looks something like this (note the name of the textarea element):
you will want to add a POST method to your page class to handle the input and run the code:
This is not something you should do with a form that is accessible to anybody you don’t trust completely, as it gives the ability to run any code they want on your web-server (e.g. they could easily try and delete all the files on the server). But if you’re ok with the security risks or just playing around, be sure to read the docs for Pythons eval to see the other arguments you can pass to it.