Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 filtering by category flask+mongodb
Hi coders! I'm dividing every page by filtering by the correct category in my recipe blog, but I don't know why I cannot manage. For example, I have vegetarian.html, It works when I simply don't look for a specific category in MongoDB, but when I do I get an error, I write here the code:

This is

def vegetarian():
    query={{"category_name": "Vegetarian"}}
    return render_template("vegetarian.html",
The error is this:

File "/Users/RBianco/Desktop/Course restart/cookbook-milestone/", line 35, in vegetarian
query={{"category_name": "Vegetarian"}}
TypeError: unhashable type: 'dict'

For sure I wrote it wrong.

Any help please?

Thank you guys!!!
Did you mean to put your dict inside a set on line 3?
(Jul-18-2020, 05:18 PM)ndc85430 Wrote: Did you mean to put your dict inside a set on line 3?

Thanks man, I just wrote query={{"category_name": "Vegetarian"}} that actually had to be query={"category_name": "Vegetarian"}

I just got confused with the {{}}

Also, FWIW, the error happens because dictionaries are mutable. If you were to change a mutable item, its hash value would change meaning that it could be in the wrong bucket in the underlying hash table. That would mean looking up the item would be broken. Dictionary keys have to be immutable things for the same reason.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  python 3.7 on windows using flask and flask-sqlalchemy. Alpy 1 352 Jul-23-2020, 10:17 PM
Last Post: mlieqo
  error when trying to update mongodb damian0612 6 210 Jul-04-2020, 07:25 PM
Last Post: damian0612
  Extract json-ld schema markup data and store in MongoDB Nuwan16 0 521 Apr-05-2020, 04:06 PM
Last Post: Nuwan16
  Flask-Sqlalchemy count products in specific category imawesome 2 364 Mar-12-2020, 08:14 PM
Last Post: imawesome
  Filtering and pagination garynobles 0 930 Jun-14-2018, 08:11 PM
Last Post: garynobles
  storing images in mongodb using python richa828 2 4,822 Jun-06-2018, 08:08 AM
Last Post: richa828
  Begginer - How to choose a server to run my Python script with MongoDB? Mapl 1 1,707 Oct-24-2017, 01:02 PM
Last Post: DeaD_EyE

Forum Jump:

Users browsing this thread: 1 Guest(s)