0

I am using the below code :

def static_info(nm):
    cursor.execute("SELECT name,age,FROM MyDB where name like ?",(nm) + '%')
    for row in cursor:
        static={"NAME: ":row[0],"AGE: ":row[1]}
    return(static)

@app.route('/submit_form')
def submit_form():
    nm = request.form.get('name')
    info=static_info(nm)
    return render_template('static_display.html',info=info)

I need the desired function output (in the form of dictionary) on my static_display.html page

Any suggestions?

1 Answer 1

1

Strange coding.

  1. Your loop in static_info(nm) will only return the last item. You're not appending anything

  2. Your @app.route('/submit_form') does not accepts POSTs. You need:

    @app.route('/submit_form', methods = ['GET', 'POST'])

  3. In your template static_display.html, you will want {{ info }}

  4. If you change your code so you can loop over a list in your template, you will want something like:

    {% for item in info %} {% for key, value in item.items() %}
    {{ key }} : {{ value }}
    {% endfor %} {% endfor %}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.