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,
0:04
I did realize that our search text would really be better off if we kept it
0:09
more optional. Let me show you what I mean.
0:11
Over here we've got our site, and we saw that we come over here and we
0:15
can say videos, search for apple, and it says,
0:19
okay, here's your page. But what we really want is like a button,
0:23
we could click, some link we could click, and take us to search and we
0:26
fill it out and notice if there's nothing there,
0:28
it says it's not gonna work right?
0:30
There's just no URL match.
0:32
It would be easier if we did it like this.
0:34
Let's take this out of here, and we'll just pass it as a query string like
0:40
this and then down in the SearchViewModel we'll just say instead of this,
0:47
we'll say self.request_dict.get("search_text: str") like so and let's make it explicit
0:54
that this is a string.
1:00
Here we go, let's try it now.
1:03
Right, we got our search and if we search for
1:08
search?search_text=apple, still works.
1:12
I guess we should print it out to make sure we're capturing the data, but we're
1:15
going to find out soon enough whether or not we're passing it over.
1:18
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.