I'm trying to get my site/page to work as follows.. (this might be conceptually wrong!)
-
user goes to my site..http://thedoordoofer.pythonanywhere.com/
-
flask_app.py runs, (hopefully the scripts identifies that it's being accessed from the root, runs some code and serves my main form (I could provide the form with the default code here, but decided to do it on the page with JavaScript)
-
the main form page for loads, identifies(JavaScript) that no parameter was added to the URL, and populates the code field with a default value.
*user on page enters a value in text box, hit submit.
- again flask_app.py is run, this time it identifies it was ran from a POST from the form, it runs some code, and then should take the user back to the form page, but this time passing back the users chosen code, so it can populate the text field or other text.
The issue I'm having is that the Flask_app.py always seems to run the "@app.route('/') def my_form():" code, and asserts that the code should be the default code (in the lots of code it uses this value to create an stl to be displayed on the form page) The end result is my page always creates and displays a default key!
What I have.. Flask_app.py
@app.route('/')
def my_form():
return render_template('form_01.html')
defaultcode = "0132X" #entering default code
# Lots of other code....
return render_template("form_01.html")
@app.route('/', methods=['POST'])
def my_form_post():
code = request.form['u']
# Lots of other code....
return redirect("http://thedoordoofer.pythonanywhere.com?code="+code)
And in my form:
<form method="POST">
<p>Code</p>
<input name="u">
<input type="Submit">
<input type="button" onclick="location.href='http://thedoordoofer.pythonanywhere.com';" value="Restore Generic" />
<form action="http://thedoordoofer.pythonanywhere.com">
<input type="submit" value="Go to Google" />
</form>
</form>
I hope this make sense, if not let me know (rolls eyes), I really just want to get this one page up and running to let people use my gadget, I had no idea that getting the page up and running was going to be such an uphill battle (and I've still to work out how to do a download button!) Any assistance would be greatly appreciated... Free doofer if someone does it for me!! LOL
Thanks, PaulP