Search Blog Posts From Navbar - Flask Fridays #31
Вставка
- Опубліковано 11 лют 2025
- In this video we'll add the search function to search blog posts for our app with flask and Python.
We've got a search bar in our navbar and in this video we'll configure it to actually search our blog posts.
We'll need to use a context processor to pass stuff to that search bar in our base.html file.
#flask #codemy #JohnElder
Timecodes
0:00 - Introduction
1:13 - Configure Search Navbar
2:55 - Create Search Function in Hello.py
3:42 - Create Search.html Page
4:25 - Create SearchForm Form
5:24 - Add Form Validation and Render Template
6:12 - Add Searched Query To Search.html
6:34 - Add Context Processor
9:06 - Create Search Query On Posts
11:27 - Add Query Results To Search.html
11:57 - Loop Thru Query Results
13:05 - Add Links To Search Results
13:55 - Conclusion
▶️ Watch Entire Flask Friday Playlist ✅ Subscribe To My UA-cam Channel:
bit.ly/3ig2eJn bit.ly/2IGzvOR
▶️ See More At: ✅ Join My Facebook Group:
Codemy.com bit.ly/2GFmOBz
▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt!
Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
▶️ Get The Code
bit.ly/2L1jBl5
Thank you for this series of fantastic videos.❤
Can’t believe this is free thanks so much for the series!
Very welcome!
Tricky and elegant. Good stuff.
thanks
I really like this series
Thanks!
Sir Elder thank you so much for the video now my request has been answered. God bless you so much
Welcome :-)
Thanks a lot for your great work! Very helpful!!
Welcome!
Now I can search 🔎 through my system using this method
What system
Hi i got a problem with the "post.searched". Where do you get the "post" from?
Go back and rewatch the videos, I walk thru it step by step
does it solved? i have the same problem
@@frengkypaw6880
it's:
post_searched not post.searched
hey John, im getting an error that says ‘method’ object is not iterable. Any clues to what could be the cause?
Edit: ahh another careless mistake😂 forgot to add brackets after the .all text
aha
hello MR John, thank you so much for your grate content even after almost 3 years it is still useful
i just have one little question
in a regular form you used "{{ form.name(class="form-control", placeholder='Name') }}" for an input
but here you used a standard HTML input tag
why did you do that and why the last version of creating an input is not working
thank you
How to reference post variable in post.searched = form.searched.data? It's red, please which video you make it avaialble globally?
just write post_searched
@@akbarhasanov4001 thanks man🥴 you saved me
@@akbarhasanov4001 gosh thank you! I was really wondering about that too and seems like I wasn't the only one
When I search for a string not found in the database it returns local variable referenced before assignment. How do I handle this? I want to return a message to the html page when the searched item is not in the database.
Hello John.. How do I for looking for more options?? Find post for the Content fiel work perfectly but I can't find the author's name in the same function Too... Thank for the help
Example:
posts = posts.filter(Posts.title.like('%' + search_input + '%'))
posts = posts.filter(Posts.author.like('%' + search_input + '%')) ## AUTHOR
Maybe it should be something like Users.query.filter(Users.username.like('%' + username + '%')) instead of posts.
Hi John, quick question for you? can you do a video on how to create or manipulate graphics or images? I want to make an Astrology program but i am not sure what library to use for the graphical Wheel that tells you what planet is in what Zodiac. .....any tips? or pointers?
Not with Flask
Hii, my assignment requires a search, and it clearly states this for a CRUD web app
"Restful microservice for searching an employee based on Name and address "
Can you please suggest me how to do that or what it means
If you don't even know what it means, you should speak with your instructor.
hello at @5.40 my post. is always getting underlined, any help please? :') Appreciate it
underlined how?
does it solved? i have the same problem
hey how can i do this with flask, vuetify and axios?
Never heard of those last two things
:( vue is a framework and vuetify is a no design skills required Open Source UI Library with beautifully handcrafted Vue Components. Axios is a promise-based HTTP library that lets developers make requests to either their own or a third-party server to fetch data.@@Codemycom
TypeError: 'method' object is not iterable
i wonder, why came out this?
please help me..!
What did you do differently from the video?
where is the post in post.searched coming from? I get an error in my code if I use that. "post is undefined"
So I'm not sure which video post gets defined in. But I was able to get it to work by defining a simple "class Post():" at the end of app.py, with a lone property of "searched: str" and then I just had to define "post = Post()" as the form validation completes.
exactly my problem..
@@aaronploetz252 i keep getting jinja2 error while trying to implement it on my code
i just got rid of the search. part :D