python - trouble querying an SQL database held on a Flask app - returning "None" in Flask when it returns data when I interact with the database -


i'm working in flask app, , i'm trying set create dynamic webpages based on data in sql database. example, if scrape data criminal, want flask route requests such can type:

myflaskapp.com/criminal/[criminal's name]/

and taken page criminal. relevant portion of views.py i've written:

@app.route('/criminal/<first_name>') def criminal(first_name):     criminal = individual_criminal.query.filter_by(first_name=first_name).first()     return render_template('user.html',                            criminal=criminal) 

now, when call individual_criminal.query.filter_by(first_name=first_name).first() in python shell, returns expected: example

however, when set flask server, , (what believe be) exact same command query, gives me blank page (with navbar , stuff extended base html.)

the html page i'm trying call simple:

<!-- extend base layout --> {% extends "base.html" %}  {% block content %}   <h1>{{ criminal.full_name }}</h1>   <hr> {% endblock %} 

as can see, should returning particular criminal's full name (in case, bryan sanford). instead, returns this: example2

instead of requested criminal's full name, way html specifies.

where going wrong here? thinking if can exact query that's in views.py file , have return correct value, should work same in flask app. however, there wires crossed somewhere. can of wonderful people me untangle this?

edit: discussed in 1 of answers comments, when change views.py include print(criminal.first_name), fails, throwing attributeerror: 'nonetype' object has no attribute 'first_name'. though exact same line works expected in actual database! enter image description here

your routing seems wrong?

this not same

myflaskapp.com/[criminal's name]/ 

as

@app.route('/criminal/<first_name>') 

try

myflaskapp.com/criminal/[criminal's name]/ 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -