python - How are jinja values returned in this context? -


i new learning jinja/flask , have relatively low comprehension far. if this, great. having trouble understanding how access values of variable here. made feeble attempt no success. errors when click "submit" button try name print on next page after "welcome, ".

alright, have index page form , return submitted value on post page shown below. however, having trouble syntax. built in pycharm flask using python/jinja2/html. of confusion exists believe.

edit_1: understand topic has several previous postings, cannot seem apply posts explain. actually, code have in here post found on here.

here python file:

from flask import flask, render_template, request  app = flask(__name__)   @app.route("/") def index():     return render_template("index.html")   @app.route("/username", methods=['post', 'get']) def username():     if request.method == 'post':        user = request.form         return render_template("username.html", username=user)     return print("something went wrong...smash computer!")   if __name__ == '__main__':     app.run(debug=true) 

here index file contains form in obtain username:

... <div id="wrapper">     <div id="title_head">     <p class="title"> gauntlet  </p>     </div>     <div id="working_area">     <form action = "http://localhost:5000/username" method = "post">         <p>enter username: <input type = "text" name = "name" /></p>         <p><input type = "submit" value = "submit" /></p>     </form>     </div> </div> </body> </html> 

and finally, here username post page (i include relevant part here):

... <body> <div id="wrapper">    <div id="title_head">         <p class="title"> gauntlet  </p>     </div>     <div id="working_area">         {% user in username %}         <p>welcome, {{ username.user }}</p>         {% endfor %}      </div> </div> </body> 

first, change user=request.form username=request.form["name"].

and then, change return render_template("username.html", username=user) render_template("username.html", username=username).

last, modify template file of username.html:

... <body>     <div id="wrapper">         <div id="title_head">             <p class="title"> gauntlet  </p>         </div>         <div id="working_area">             <p>welcome, {{ username }}</p>         </div>     </div> </body> 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -