python - how to run .py script with user input as parameters -


i have .py file, 'car.py'. takes 3 inputs (color, make, year). takes user input , reads file, returns matching instances of color, make, , year given in input. script runs fine.

now, create web page works search page. asks 3 inputs, searches file (locally) , returns results.

i using django first time , having difficulty figuring out how call car.py file , have run on background before returns result.

i have html interface made know cant ref python script in it. there similar in django? can reference script , when button pressed, it'd run script given user input?

i don't expect full coded response, want clarification or reference answer. haven't been able find similar online.

gonna move response of how submit form in django here instead of comment, since it's more of answer now.

when submit form, typically post request sent website form's values in it. when form submit route, mean post request sent particular view in django website, view car.py file few changes. here's an example of form, take in 3 desired inputs, , here's an example of view "car.py", , a template.

a rough example of view:

def search_view(request):     if request.method == 'post':         form = searchform(request.post)          if form.is_valid():             # process data code "car.py"             # render results page             return render(request, 'results.html')     # if (or else) render same search page again     else:         form = searchform()     return render(request, 'search.html', {'form': form}) 

searchform() can whatever values want user.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -