How can I call a python script when the button is html file is clicked? I am trying to change the language of the website by clicking the button. This is what I have done so far, but I am getting an error when I hit the button "page not found" and "The current URL, foo, didn't match any of these." What am I doing wrong
login.html
<form action="/foo" method="post">
<input type="submit" name = "first_button" value="French">
<input type="submit" name = "second_button" value="Spanish">
</form>
views.py
from app import foo
def get_language_from_client(request):
new_lang= foo()
if new_lang=="fr":
client_lang="fr"
else:
client_lang = translation.get_language_from_request(request)
print "client_lang:", client_lang
if "en" in client_lang:
return 0
elif "nl" in client_lang:
return 1
elif "fr" in client_lang:
return 2
elif "pl" in client_lang:
return 3
elif "ru" in client_lang:
return 4
else:
print "Unknown language code:", client_lang
return 2
app.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('login.html')
@app.route('/foo')
def foo():
return "fr"
if __name__ == '__main__':
app.run()
My directory structure looks like
scriboxapp
-templates
-login.html
-views.py
-app.py