jeudi 16 mars 2017

Django Help: How to take text data from textbox and pass through python script?

I'm making a Django web app where I want to take user input from an HTML textbox and run it through a python script. The script works when I input text from the command line, but I want to be able to make the web app print what happens to the text when it goes through the script.

I have already made a Django web app, and when the server is run a basic HTML page with a simple text box and a submit button appears (it's a form).

I have written a separate python script which will take user input (from the command line) and run the text entered through the script.

How would I be able to replace the input() from the function with form data from the HTML page?

An example of what I want to do:

<form action="">
text: <input type="text" name="handle" value=""><br>
<input type="submit" value="Submit">
</form>

The above is a simple form with the submit button. When the 'submit' button is pressed, I want that data to go to a script:

import statements

def blah():
screenname = input('Enter your name here: ') 
output = screenname.functionA
print(output)

Except the input() is replaced with the form data from the HTML file.

Where would I store the python script in the Django app?

How would I pass the text from the form to the python script?

Any help is appreciated, I'm trying to develop my web design abilities one step at a time :)




Aucun commentaire:

Enregistrer un commentaire