HTMX + Flask: Modern Python Web Apps, Hold the JavaScript Transcripts
Chapter: Feature 2: Active search
Lecture: Search text is better as an optional URL element

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now before we leave this, adding this general structure for search, I did realize that our search text would really be better off if we kept it
0:10 more optional. Let me show you what I mean. Over here we've got our site, and we saw that we come over here and we
0:16 can say videos, search for apple, and it says, okay, here's your page. But what we really want is like a button,
0:24 we could click, some link we could click, and take us to search and we fill it out and notice if there's nothing there,
0:29 it says it's not gonna work right? There's just no URL match. It would be easier if we did it like this.
0:35 Let's take this out of here, and we'll just pass it as a query string like this and then down in the SearchViewModel we'll just say instead of this,
0:48 we'll say self.request_dict.get("search_text: str") like so and let's make it explicit that this is a string. Here we go, let's try it now.
1:04 Right, we got our search and if we search for search?search_text=apple, still works.
1:13 I guess we should print it out to make sure we're capturing the data, but we're going to find out soon enough whether or not we're passing it over.
1:19 That's just an easier way for us to have both a page where we say search that we just go to and then also pass search_text along for deep linking.

Talk Python's Mastodon Michael Kennedy's Mastodon