render_template with multiple variables

Afeez Aziz :

I am using Flask(as framework) and MongoDB(as database server). Right now, all i can do is just pass one argument that i got from the database:

@app.route('/im/', methods=['GET', 'POST'])
def im_research(user=None):
    error = None
    if request.method == 'POST':
        if request.form['user']:
            user = mongo.db.Users.find_one_or_404({'ticker':request.form['user']})
            return redirect(url_for('im_user',user= user) )
        else:
            flash('Enter a different user')
            return redirect(url_for('im'))
    if request.method == 'GET':
       return render_template('im.html', user= None)

How do i pass multiple variables from the database: eg: in my Mongo database: i have these things in my database and i would like to pass them all to my template.

{
users:'xxx'
content:'xxx'
timestamp:'xxx'
}

Is it possible to do that by using Flask?

heat :

You can pass multiple parameters to the view.

You can pass all your local variable

@app.route('/')
def index():
  content = """
     teste
   """
  user = "Hero"
  return render_template('index.html', **locals())

or just pass your data

def index() :
    return render_template('index.html', obj = "object", data = "a223jsd" );

api doc

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to use flask render_template API to return multiple images for a HTML template in the template folder?

Flask render_template() & **locals() arg not working... Won't display python variables in HTML text

How to render multiple Component-type variables through a template

NgIf multiple template variables

Django passing multiple variables in render

Pass multiple variables in helm template

dynamic render_template() in flask

Empty list in render_template

Pass multiple variables to render json in rails cotroller

Can you declare multiple with variables in a django template?

Sending Multiple Dictionary Variables as one in Template

How to pass multiple variables to Go HTML template

Polymer multiple variables next to each other in template

How to execute multiple variables in HTML Go Template?

vuejs :: Render template using variables

Difference between render_template and redirect?

Show HTML table with Flask and render_template

Flask : render_template handling dataframe as html

Python Flask not displaying contents with render_template()

Re-rendering with render_template not working

Flask render_template with function return

flask render_template with url parameter

Flask's render_template() issue

Optional keyword argument in render_template

Flask render_template is not passing context properly?

Passing parameters with flask render_template()

Rails 4 Passing multiple variables through render partial

Multiple mutexes for multiple variables

Multiple if statements for multiple variables