Latest / Talk Python To Me / #321: HTMX - Clean, Dynamic HTML Pages
Transcript
- 0:00Have you wanted to add more interactivity and liveness to your web application?
- 0:03If you built it using Flask, Django, or some other Python web framework,
- 0:07that thought probably didn't fill you with joy. And that's because it might mean you need to
- 0:12change a bunch of your code and rewrite a significant bit of your application
- 0:15using a full-on front-end web framework like Vue.js or React.js.
- 0:20In this episode, we meet Carson from Big Sky Software. He's the creator of HTMX.
- 0:25This front-end JavaScript library lets you leverage the server-side aspects of your Python web app
- 0:31and add amazing interactivity, but keep the logic on the server near the database and implement it in Python.
- 0:36You're going to love it. This is Talk Python To Me, episode 321, recorded May 25th, 2021.
- 0:43Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities.
- 1:02This is your host, Michael Kennedy. Follow me on Twitter where I'm @mkennedy,
- 1:06and keep up with the show and listen to past episodes at talkpython.fm,
- 1:10and follow the show on Twitter via at Talk Python.
- 1:13This episode is brought to you by Sentry and Your Base,
- 1:16and the transcripts are brought to you by Assembly AI.
- 1:19Please check out what they're offering during their segments. It really helps support the show.
- 1:23Carson, welcome to Talk Python To Me.
- 1:25Thank you. I'm really happy to be here.
- 1:27I'm very thankful that you're willing to go a little bit outside the lines of a normal Python development
- 1:33to talk about something like HTMX.
- 1:35You know, I'm extremely happy to see HTMX getting picked up,
- 1:39particularly by the Django community in Python,
- 1:42and so I was very excited to come on here.
- 1:44Yeah, I'm really excited to have you here.
- 1:46It is such a cool technology,
- 1:48and I think so often the JavaScript story is,
- 1:51oh, you're doing this other technology that you like.
- 1:55Let us tell you how you should drop that and go do JavaScript, right?
- 1:58And what I feel HTMX brings is whatever technology using Django, Flask,
- 2:03even some other thing like Rails or ASP.NET,
- 2:07whatever it is that you already got working really well,
- 2:09here's a really cool way to extend that.
- 2:12We're going to dive into that.
- 2:12So I think, you know, I've had people reach out and say,
- 2:16oh, I'm a JavaScript developer.
- 2:18Let me come on to your podcast and tell people about how cool Node is.
- 2:21I'm like, well, I'm not really sure that's the best topic for a Python-focused podcast,
- 2:25so I'm going to decline your invitation,
- 2:27but I was really happy to get a chance to have you on the show
- 2:30because I think there are many people out there who are nervous about JavaScript.
- 2:36They're not yet learning JavaScript.
- 2:38They know they need some interactivity,
- 2:40and they feel that means they have to abandon what they've already learned
- 2:44or what they actually love, and I don't think that's the case.
- 2:46And we're going to dive into that.
- 2:48So I think HTMX plus Python web frameworks is a beautiful thing.
- 2:52But before we get into that, let's just start with your story.
- 2:54How did you get into programming and, yeah, start there?
- 2:58Sure.
- 2:58Well, I've been programming for a very long time now,
- 3:01and I started programming in college back in 94.
- 3:04Actually, before that, I was programming on a Mac and HyperCard,
- 3:08which is a very old technology, which I love.
- 3:11The web before the web.
- 3:13Yeah.
- 3:13Like local web.
- 3:15I can talk about that.
- 3:16If we talk about HyperScript at the end, maybe that'll come up again.
- 3:20But I started programming in college and then very early on started programming for the web back when it was CGI scripts and Perl and stuff like that.
- 3:28And then I moved into Java during kind of the original .com boom and did a lot of the was in the Java world for a long time and eventually moved into Rails.
- 3:39And so I've been programming in Rails now for the most part.
- 3:42I do.
- 3:43I program in a lot of different stuff, though, mainly Java and Rails.
- 3:47And I have to admit to your audience, please don't judge me too hard.
- 3:50But I haven't used Python very much in anger.
- 3:53I've used it for local sort of sysadmin scripts, but not for a bunch of web development.
- 3:58So but, you know, Rails and Django share a lot of things in common with one another.
- 4:03And they're both great server side pieces of infrastructure.
- 4:07And I always felt like it was a shame that they were kind of being left.
- 4:11They were being ignored to a large extent by the by the bigger JavaScript frameworks.
- 4:16One term that I try and coin, there's a lot of different stacks out there, right?
- 4:20Like the lamp stack and so on and so forth.
- 4:22And one joke stack that I've made up is the Howl stack, which is hyper.
- 4:27Howl? H-O-W-L?
- 4:28H-O-W-L.
- 4:29Okay.
- 4:30So HTML on whatever you'd like.
- 4:32So use HTML on the front end and then use whatever you'd like on the back end.
- 4:37Nice, nice.
- 4:38HTMX is really empowering for this, right?
- 4:40I mean, that's kind of the philosophy in some degree.
- 4:42I mean, you get a joke stack, but like literally that's.
- 4:44Yeah.
- 4:46It's a joke, but it's kind of true.
- 4:47So.
- 4:49Yeah.
- 4:49Yeah, absolutely.
- 4:50And how about now?
- 4:51What do you do day to day?
- 4:52So day to day, I teach part-time at a university.
- 4:54My passion is actually programming languages.
- 4:57So I teach that as well as some other classes at a university part-time.
- 5:01And then I also, I work for a startup as well that I've been working on for a long time and
- 5:06which uses Intercooler.js, which is the predecessor at HTMX.
- 5:10The story with HTMX was that, well, we can go into it in a little bit if you'd like to,
- 5:14but that's what I'm doing now.
- 5:15So kind of a mix.
- 5:17I find myself doing a lot of different stuff.
- 5:19Yeah.
- 5:20That sounds like a really nice mix.
- 5:21I love universities.
- 5:22I love university campuses.
- 5:24Maybe it's a slightly different story today with COVID, right?
- 5:28But I think we'll kind of get back to it.
- 5:30But some of my fondest memories are just, you know, spending time dreaming about ideas,
- 5:35walking around various campuses.
- 5:36Yeah.
- 5:37It's a good energy.
- 5:38The kids aren't quite as beaten down.
- 5:40Some of the, when you're in the corporate sector, I mean, you see a lot of these posts
- 5:44on Hacker News and so forth, just old guys, older guys and gals that are just sick of the
- 5:49sick of the grind.
- 5:50And so it's nice to be around younger kids that are maybe not quite as jaded and there's
- 5:55just an energy and, you know, it's a beautiful environment.
- 5:58Yeah.
- 5:58Keeps you young being around that crowd.
- 6:01I do think that's awesome.
- 6:02So I want to start our conversation by taking a little bit of a step back.
- 6:06And I think we've circled around this a little bit, but when people are working in some technology,
- 6:13let's focus on Python, but it could be Rails, like you had said before, and they've got something
- 6:18working really great.
- 6:19You come to some part of the site and it's like, well, this should be really interactive.
- 6:23Like I want to click on this thing.
- 6:25And depending on what I select here, I want that dropdown to select that other thing.
- 6:29Or as I search here, I want it to actually just fill it as I type.
- 6:34I don't want to have to type in the search text, hit enter, see what comes back from the
- 6:38server.
- 6:38Oftentimes that is sold as a, well, your site is going to be more responsive if it's running
- 6:45on the front end.
- 6:45And sometimes that's sort of true, but I feel like a well-designed website can be really
- 6:51responsive.
- 6:51Like I don't really feel like the speed thing is the story, but this interactive like navigation
- 6:55thing where it resets where it is, like that is a real challenge.
- 7:00And so often people get pulled down this path, right?
- 7:03Well, you want to have that experience.
- 7:05So is it Vue.js or React?
- 7:08What are you going to do?
- 7:09And then 10,000 lines later, a front end code, you've winnowed down your backend to
- 7:14just a couple of simple HTTP API methods.
- 7:17Then also something that serves up like a HTML static page.
- 7:22And then the question becomes, well, why are we doing Python or why are we doing Rails at
- 7:27all?
- 7:27Why don't we just do Node on the backend and we just have that as our entire stack?
- 7:32I feel a lot of times people either end up going down that path and throwing the baby
- 7:38out with the bathwater type of thing, right?
- 7:40Like you have this really cool server side ORM and a bunch of stuff happening that you really
- 7:45love from your server side, say Django or whatever, but you kind of already gone.
- 7:51Like you're just so close.
- 7:53You're just like, well, let's just, we're already mostly writing JavaScript.
- 7:55Let's just write JavaScript.
- 7:56So I think that's one side of the story.
- 7:58And I think there's real pressure on the other web frameworks and Python and other spaces
- 8:02for that.
- 8:03The other side is people who are not doing that, but they feel bad.
- 8:06They're like, I know I'm doing it wrong.
- 8:09I know I'm not using React.
- 8:10I'm just using Django, but this is all I know.
- 8:14And I just not ready or we're just not a big enough team.
- 8:16How's that sit with you?
- 8:17What do you think about this?
- 8:18Yeah, I didn't like that.
- 8:20That's exactly the pressure.
- 8:21I don't like it either.
- 8:22That's why I'm so excited about HTMX.
- 8:24That's exactly the pressure that I felt on Rails.
- 8:27I liked Rails.
- 8:28Ruby is a programming language I'm so, so on.
- 8:31It's fine.
- 8:32It's got its issues.
- 8:33But I liked Rails quite a bit.
- 8:35And I just disliked that pressure to adopt something else on the backend that came with using these
- 8:41more complex JavaScript frontends.
- 8:43And like I said earlier, it was just a shame.
- 8:46And the other aspect of that is when you go to that model, when you go to the Vue.js or the
- 8:51React model, your backend becomes pretty dumb.
- 8:54It's just producing JSON.
- 8:56You know, there's validation code.
- 8:58And, you know, yeah, your validation code can now live on both sides, which is important
- 9:02because the front end is not a trusted computing environment.
- 9:05So you can't trust validations that are done on the front end.
- 9:07You always have to redo them.
- 9:08You just redo them again anyway.
- 9:10That's right.
- 9:11So there's just all these kind of, I don't think they're complete arguments, but just, it's just with the grain to start pushing JavaScript onto the backend, especially once Node really came out and gave JavaScript a good runtime on the backend.
- 9:24And it's not a good thing.
- 9:26And the reality is, is I hope we can demonstrate with HTMX today that a lot of very good UI or slash UX patterns from the web can be achieved using just HTML, using the original HTML model, the original RESTful model for the web.
- 9:44I know that's kind of a fancy term, but just using the original model of the web, just kind of generalizing what we're already familiar with in our day-to-day development, links and forms.
- 9:54That's where HTMX is coming from is this idea.
- 9:57Wait a second.
- 9:58Let's take a step back.
- 10:00We don't need a super complicated front end.
- 10:02We just need to improve HTML.
- 10:04Right.
- 10:05We don't have to push it all down to the front end.
- 10:07Right.
- 10:07We only need to push a little bit of that interactivity down, right?
- 10:10That's right.
- 10:11And that interactivity can be defined in terms that are very familiar to us from normal HTML.
- 10:17So let's just take HTML and try and push it as a hypermedia or hypermedium, I guess I should say.
- 10:25People get mad because hypermedia is plural, but I say it.
- 10:29So, you know, that's where HTMX is coming from.
- 10:32It's very similar.
- 10:33You know, this frustration with the industry, particularly.
- 10:37I don't think this is strong now because Python has had, I mean, you go and you look at the trends and Python is just crushing right now.
- 10:43Yeah.
- 10:44It's such a, not a resurgence, but such an acceleration from where it was.
- 10:48Right.
- 10:48You know, 10 years ago.
- 10:50And I think if you compare that with five years ago, JavaScript was really the thing that was accelerating the most.
- 10:55I don't think that's true today.
- 10:56I think JavaScript is maybe plateauing a little bit.
- 10:58There's still plenty of JavaScript out there, obviously.
- 11:01But I feel like Python is really taking off because of, you know, big data and some of the AI tools that are available in Python.
- 11:09And so some of the great older tools like Django and Flask that have been around for a long time and that do a good job.
- 11:15So, again, just a very similar situation with you where I'm looking at this going, man, this stinks that you have to become either like a killer JavaScript front end engineer and then have two languages that are pretty complicated or abandon whatever backend you prefer in favor of JavaScript.
- 11:35Yeah.
- 11:35I'm 100% with you.
- 11:36Let me pull up a couple of things.
- 11:37One, here's that graph that you were talking about.
- 11:41Yeah, that's exactly the graph.
- 11:42Of Python going pretty wild.
- 11:44Like, you talked about JavaScript plateauing.
- 11:47So this is the stack overflow, you know, stack overflow trends for the major programming languages.
- 11:52So this is really surprising to me and I find it quite interesting here.
- 11:56Yeah.
- 11:56Also, a couple of things from the live stream.
- 11:58Nick Harvey.
- 11:58Hey, Nick says, for me, it's a constant battle between all the benefits of server side.
- 12:03Plus, I don't want the page to keep refreshing.
- 12:05Yep.
- 12:06I sympathize, Nick.
- 12:07And that's exactly what HTMX is designed to help with.
- 12:10The real bad part about the original web and browsers, we have to say, I think you made this point earlier, Michael.
- 12:16Browsers have gotten better at making the page transition not quite as clunky visually.
- 12:22So you can do sort of web 1.0 style apps and get away with it for a lot of stuff.
- 12:27Yeah.
- 12:28You talked about doing programming in 94.
- 12:31And I remember the first mosaic that I saw that was the graphical web.
- 12:36And I was just, my jaw was just dropped.
- 12:39I'm like, this changes everything.
- 12:41I've been using Telnet and like Gopher and all sorts of crazy stuff.
- 12:46Oh my gosh.
- 12:47And I'm just like, this is a new world.
- 12:49I literally think I had to skip the next class I was supposed to go to because I'm like, I can't, I have to explore this.
- 12:54This is unbelievable what I've just found.
- 12:56But I remember it going clunk, clunk.
- 12:57You could just see it building the page as it comes.
- 13:00And that was, yeah, luckily it's not like that.
- 13:03It's the big problem.
- 13:04It is, you know, it's much better now, but it's still a problem.
- 13:07And it's a big problem for many UX patterns.
- 13:09You just, you don't want it.
- 13:10And that's exactly what HTMX is designed to help with.
- 13:15So you can stay within that original model of the web.
- 13:17You can use whatever backend you want to produce your HTML, but we can get better user experience out of it.
- 13:23Yeah.
- 13:23Yeah.
- 13:24So also RJ out there in the live stream says, I just discovered HTMX a few days ago.
- 13:29Great timing.
- 13:29This portion of Talk Python I May is brought to you by Sentry.
- 13:34How would you like to remove a little stress from your life?
- 13:37Do you worry that users might be having difficulties or are encountering errors in your app right now?
- 13:42Would you even know it until they send that support email?
- 13:46How much better would it be to have the error and performance details immediately sent to you, including the call stack and values of local variables and the active user recorded in that report?
- 13:56With Sentry, this is not only possible, it's simple.
- 13:59In fact, we use Sentry on all the Talk Python web properties.
- 14:03We've actually fixed a bug triggered by a user and had the upgrade ready to roll out as we got their support email.
- 14:10That was a great email to write back.
- 14:11We saw your error and have already rolled out the fix.
- 14:14Imagine their surprise.
- 14:15Surprise and delight your users today.
- 14:17Create your Sentry account at talkpython.fm/sentry.
- 14:21And if you sign up with the code talkpython2021, it's good for two months of Sentry's team plan, which will give you up to 20 times as many monthly events as well as other features.
- 14:32So just use that code talkpython2021 as your promo code when you sign up.
- 14:37Yeah, so speaking of which, let's go ahead and let's get into it, right?
- 14:42So we've set this up as a, it doesn't have to be either or.
- 14:46It doesn't have to be either Django or Flask or React or Vue, right?
- 14:51Like, it doesn't necessarily have to be that way.
- 14:53And there's some really cool stuff going on here.
- 14:55Like, let me just read this little introduction you got over here at htmx.org.
- 14:59It says, htmx allows you to access AJAX, CSS transitions, web sockets, server sent events directly in HTML just using attributes so you can build modern interfaces simply.
- 15:10Which is really nice.
- 15:11And one of the things that frustrates me about these frameworks, like I do some stuff in Vue and like, I'm not against it.
- 15:18I just want to put out there, I realize there are apps that are absolutely making sense to build with Vue or with React, right?
- 15:25Are you trying to build a mobile app that is really sort of a progressive web app?
- 15:30Like, oh, that should absolutely be in that.
- 15:32Are you trying to build Gmail?
- 15:35It should very likely be in something like Vue.
- 15:38But most of us just want a sprinkling, like a little salt, you know, a little bit of niceness here and there to our app.
- 15:45And in order to get that, these days JavaScript has moved so far that it's no longer this simple little language that you just include a tag and then to the file and you're good to go.
- 15:55It's like you've got Webpack and you've got CLI tools and you've just got all this stuff to go, right?
- 16:01So what's the getting started experience for htmx?
- 16:05Yeah, htmx looks pretty straightforward here.
- 16:07Yeah, it's a small, it's a no build library.
- 16:11So there's no build step associated with it.
- 16:14You just drop it in.
- 16:15I mean, you can use a CDN if you want.
- 16:16The starting experience for it can be as simple as just adding a single attribute or maybe two attributes would be the minimum thing.
- 16:23And so it's not, it doesn't require a total rework of your front end.
- 16:28And that's one thing, you know, one concept I like to talk about with my students is this idea of a complexity budget.
- 16:33Your application has a complexity budget.
- 16:35You need to spend it effectively.
- 16:37And so with htmx, you can pick the parts of your app that need it and add interactivity to them.
- 16:43And the remainder of your app can remain just a standard, you know, web app that works the normal way.
- 16:49And because of that, you can sort of spend your complexity budget where you want to on your app rather than saying, okay, we're going to, we're going to react.
- 16:58And now we need a react router.
- 16:59And now we need GraphQL.
- 17:00We need all this stuff to make.
- 17:03Our next sprint is going to be the rewrite sprint.
- 17:05Right.
- 17:06I hope it's, you know, people would agree that it's, it's a lightweight library in that sense.
- 17:11And that you don't, you don't need to do a whole lot to make things work within one particular.
- 17:16There's some attributes like HX boost, for example, that you can just kind of toss on your, you know, on the body tag and it'll turn all the links into Ajax requests and all the forms into Ajax submissions.
- 17:27And so it's kind of like a turbo links, if you're familiar with that technology and that sense.
- 17:32So we, you know, there's, that isn't a big focus of the library, but it's there as well.
- 17:36So hopefully relatively lightweight and the user experience.
- 17:41I was going to say, so you basically include a script tag to link to HTMX, 10 kilobytes and it has no dependencies.
- 17:49Yep.
- 17:51Yeah.
- 17:51RJL out there in the live stream says, I strongly believe that these JS libraries, speaking of view and react and whatnot, are overkill for the majority of CRUD apps that exist on the web.
- 18:00Probably 90% of the CRUD apps are built within private corporations.
- 18:03And I've been doing that since 94.
- 18:05And then also does npm and web pack are both a blessing and a curse.
- 18:09Yeah.
- 18:10Especially if you're a backend sort of person.
- 18:12Yeah.
- 18:13I never liked big, complicated build tools in any, you know, in any, even on the backend, I just, I'm not a big fan of them.
- 18:21I like dependency managers, but beyond that, I don't want a bunch of stuff going on.
- 18:25Yeah.
- 18:26I'm with you on that as well.
- 18:27All right.
- 18:28So let's talk about the motivation that you got here before we get into some code, because I think it really sets the stage.
- 18:34I mean, obviously we've, we've been studying the motivation here, but you know, you throw out some questions, some hypotheticals like, Hey, why should only anchor tags and forms be able to make HTTP requests?
- 18:46Like if I click on an image, shouldn't it be able to make an HTTP request?
- 18:51Why should click and submit be the only events that trigger them?
- 18:54Right.
- 18:55Like I don't know, mouse over or key down or something like that.
- 18:58Right.
- 18:58Probably key down for a smart auto-complete search.
- 19:00Why should only get and post be available?
- 19:03And why should you, why should they only replace the entire screen?
- 19:06Yeah.
- 19:07And that last one's really the crux for what Nick was talking about earlier, right?
- 19:11Is web requests have to do this big, chunky, replace the whole screen.
- 19:17If you have an action that only updates a small amount of that screen, why not just return the HTML for that small amount of the screen?
- 19:24And then in that element that's issuing that request specify, Oh, put the return content into that thing.
- 19:32And that's exactly that.
- 19:34So HTMX has an attribute called HX swap that lets you, or excuse me, HX target that lets you say exactly where you want to place the return to content.
- 19:44And then HX swap is another attribute, which lets you tell HTMX exactly how to do that swap.
- 19:50If you want to replace the whole thing or just the inner content or append it or whatever.
- 19:54So let me lay out an example here of a type of app that feels like it would need view or something.
- 20:00I'm just going to pick on view.
- 20:02It's like the catch all for all the major front end frameworks going forward.
- 20:06So imagine I've got like a photo gallery of like five images up on the screen.
- 20:12And I want to be able to click on that image and then have like a details of it.
- 20:16Like maybe the exit tags or like where it was taken or other stuff stored about it on the server.
- 20:22Maybe it's like a Wikipedia thing and like you click on the picture and it gives you some details about the picture below.
- 20:28And you just want to keep that there.
- 20:29And as you click on them, maybe even use an arrow keys or click around between them and have that happen.
- 20:34That's the kind of thing you're talking about, right?
- 20:36Like I could set it up so I could have an event where I interact with the image and it does a swap.
- 20:42And explain to me what I have to write in order to get that bottom part to like reload.
- 20:47Yeah, all you would do is on that image, you would say HX get and you would give it the URL to get that information from.
- 20:53And that information would come back in HTML form.
- 20:55And then you would say HX target.
- 20:58And there would likely be a div down below that would be your details div.
- 21:03And let's say it has the ID details.
- 21:05So your HX target attribute in that case would be hash details.
- 21:10And that tells HTMX when this request comes back, take that content and jam it into the details div or whatever that has the ID details on it.
- 21:19Yeah, so that bottom section.
- 21:20And then if you want to, you know, depending on how you want to do that swap, the HX swap attribute lets you say inner HTML.
- 21:26Default is inner HTML.
- 21:27So it'll swap that into the inner HTML.
- 21:30But maybe you want to replace the whole thing for whatever reason.
- 21:32You could say HX swap outer HTML.
- 21:36And then there's a bunch of attributes there.
- 21:38And there's some syntax in there.
- 21:40Let's see, control scroll state, whether or not something gets pushed into history, depending on how you want to do that and so forth.
- 21:47And so there's a lot of stuff like that that lets you determine exactly how that swap is going to happen.
- 21:54Yeah.
- 21:54Fantastic.
- 21:56So right on the home screen, you've got kind of an example that is commented.
- 22:03Without the comments, it's four lines of HTML.
- 22:07Right.
- 22:08And that's the entire application.
- 22:10I guess you probably would want to wrap that in like an HTML and a body tag.
- 22:14But beyond that, right?
- 22:15So what you do is you include the script and then you have a button.
- 22:18And on the button, you have an attribute that says HX-post equals slash clicked.
- 22:24Then you have your HX-swap equals outer HTML, presumably of the button.
- 22:30Right.
- 22:30So you could say click the button and the button would replace with like a map of where you are or a grid of results or whatever the heck the returned HTML from slash clicked is.
- 22:41Right.
- 22:41Yeah, that's right.
- 22:42And it's HX-post, right?
- 22:43Is that what you said?
- 22:44Yeah.
- 22:44HX-post.
- 22:45I probably said it wrong.
- 22:46But yes, exactly.
- 22:47That's what I meant.
- 22:48Oh, no, it's okay.
- 22:48I just want to make sure.
- 22:49Yep.
- 22:50Yeah, yeah.
- 22:50Keep me honest.
- 22:51No, it's all good.
- 22:52It's hard to do code visually.
- 22:53My screen is flickering again.
- 22:55So I want to make sure I'm on the same page as you here.
- 22:57Yeah, yeah, yeah.
- 22:58This is just a quick start at the homepage.
- 22:59This is so neat because when people think about all the stuff they have to do, in order to adopt this type of dynamic page that you're talking about, what you have to do is you have to have a method on the server, a view method on the server that returns
- 23:17HTML fragments.
- 23:18Right.
- 23:19Instead of returning, you know, the whole HTML body, whatever.
- 23:22Like if my story where I said I'm going to put a grid of results, you have to have a server side thing that can generate HTML for a grid.
- 23:30Right.
- 23:31So you could do that with like a template like a Jinja or a Django template or a Chameleon template on the server and just pull the data out of your database, bind it.
- 23:41And instead of returning, have your template contain a full bit of HTML.
- 23:44It's like an HTML fragment.
- 23:45Yeah.
- 23:46Exactly.
- 23:47Exactly.
- 23:47In Rails, they're called partials.
- 23:49That's the language the Rails community uses.
- 23:51But it's just a sub-template.
- 23:53And so typically what you would do in an HTML based application is you would have your normal templates and then they would include these sort of sub-templates or partials, again, to use the Rails terminology.
- 24:07And so the HTML kind of pushes the factoring problem to the back end.
- 24:10So you factor your templates out on the back end rather than maybe creating components on the front end is how someone more familiar with Vue might think about these things or React.
- 24:20Yeah.
- 24:21It's like the little component bit on the server side there.
- 24:23Yeah.
- 24:23Yeah.
- 24:24So you do your factoring on the back end and then hopefully you're designing a good URL schema, a nice RESTful URL schema, and it all kind of makes sense with sub-resources and so forth.
- 24:34Right.
- 24:34So in this example, there's just a button.
- 24:36It just goes to slash clicked.
- 24:38But in my scenario where I had five images, the URL, like the hx-post could be slash detail slash one, slash detail slash two.
- 24:51And when you render the original HTML, you can preload into those embedded pieces the right data to pass on when it gets clicked or it gets interacted with.
- 25:02Right.
- 25:02Yeah, exactly.
- 25:03So that image is a resource.
- 25:05If we're thinking restfully, that image is a resource on the server.
- 25:09And so it has a URL associated with it.
- 25:12Let's say images slash one.
- 25:14Let's just say that.
- 25:15And then images slash one might have a sub-resource of images slash one slash details.
- 25:21And so you would, you know, you render that image slash ID slash details is what returns the details you were talking about earlier.
- 25:30And you would probably use hx-get in this case because it's a, you're retrieving information without a mutation.
- 25:36So post is probably not an appropriate HTTP verb or action to use.
- 25:42And so you would get that and then, you know, slam it into the div below the images.
- 25:47Right.
- 25:47That's almost exactly what you would do if you were going to write a server-side only thing.
- 25:53Right.
- 25:53It would just pull up that details page and it would have a back button to get to the other ones or something like that.
- 25:58Or maybe it would reload the whole page and then just stuff that in the bottom.
- 26:01Yep.
- 26:01So the experience of writing is almost, it's almost unchanged, right?
- 26:05You get to fully leverage the server-side thing.
- 26:08It is.
- 26:08And that's a great point.
- 26:09It's very similar to a link, right?
- 26:11And the advantages here are that you don't have that clunky user experience.
- 26:16You do have a smaller payload.
- 26:18That tends not to matter that much.
- 26:20People make a bigger deal out of that than I think is necessary.
- 26:23Yeah.
- 26:24But it really retains that simplicity.
- 26:26And on top of that, you also have all these tools that have been developed over the last 20 plus years of web development that are suddenly available to you again, such as caching and SQL tuning on the backend and so forth.
- 26:38All that institutional knowledge that we've built up about how to create good, fast web applications applies using the HTMX model in a way that is not as obvious if you're front end.
- 26:51You know, there's a whole separate style of development for developing JSON APIs at this point that just doesn't have a lot to do with that original model.
- 26:59And so we're relearning things.
- 27:01How do you, you know, that's, that model is really RPC, remote procedure call, I think.
- 27:06And so that is just a different mindset than the hypermedia infrastructure that we're used to as web app developers.
- 27:13Yeah, for sure.
- 27:15So you talked about this complexity budget before.
- 27:18And one of the things I like about this is I can have already built my application and I can decide, you know what, it would be a lot better if instead of doing a full refresh for this part, we could just add some interactivity to this.
- 27:33Right.
- 27:33Right.
- 27:34It feels to me like it's very easy to go to an existing web app and add this more dynamic nature to it.
- 27:41Yeah.
- 27:42In certain focused areas with HTMX.
- 27:44Yep.
- 27:44Exactly.
- 27:45You know, that's, again, I advocate for that.
- 27:47I think a good MVP written in the web 1.0 style can validate your app.
- 27:53You can start getting feedback very quickly without this really expensive from in development terms, front end investment in your technology.
- 28:01And then once that works out, you can start seeing how users are using your app and improving it from there.
- 28:07And so it lets you delay committing your complexity budget deeper into the development process.
- 28:14I think that's a big advantage of these lighter weight front end frameworks.
- 28:17Alpine JS is another one that I think lets you do that to an extent.
- 28:21You can just kind of sprinkle in when you want.
- 28:23And in fairness, I have heard people say that Vue can also be used in this way.
- 28:28So I don't want to say that's exclusive.
- 28:31Yeah.
- 28:31Yeah.
- 28:32If I had to pick a rich front end framework, Vue is certainly where I feel really happy.
- 28:36because while it does have the CLI stuff and it does have a lot of that style, it also has ability to just drop in a JavaScript file for Vue JS and then indicate here's a sub tag or some subset of my page.
- 28:52And now that's the app.
- 28:53Make this page go right there.
- 28:55There's that nice aspect.
- 28:56But yeah, I just feel like the, you still get to do all the important stuff on the server here, which is pretty cool.
- 29:03Yeah.
- 29:04Yvonne out in the live stream says, I heard about HTMX at DjangoCon EU.
- 29:08Really like the project.
- 29:09Fire, fire emoji.
- 29:11Yeah.
- 29:11We got a lot of mentions at DjangoCon EU and I'm hoping we'll get a bunch at the US DjangoCon as well.
- 29:19And, you know, I'm not, again, since I'm kind of, I have to, again, admit a little bit of an outsider in the Python community.
- 29:26You know, I'm hopeful that I can make more contacts and really help HTMX help Python developers stay in Python.
- 29:34So, yeah.
- 29:36Do this more.
- 29:36Do you provide better user experience for your users, but also stay within the Python world.
- 29:42It's, you know, obviously just, it's growing gangbusters.
- 29:45So.
- 29:46Yeah, for sure.
- 29:46Well, if your screen is willing.
- 29:49Yeah.
- 29:50Actual screen on your, like actual monitor is willing.
- 29:53Let's look at some examples.
- 29:55So.
- 29:55And I have to admit, I'm flying blind right now.
- 29:58My screen is blinking on.
- 30:00All right.
- 30:00So, but.
- 30:01Hopefully you're, I'll try to describe it.
- 30:03Yeah.
- 30:03I've got my phone up so I can follow along.
- 30:05Yeah.
- 30:06Perfect.
- 30:06Sorry.
- 30:08Linux.
- 30:08No, no, no.
- 30:09It's all good.
- 30:10It's all good.
- 30:10For just people listening.
- 30:12It's not that like the screen sharing is not working.
- 30:14Like the actual whole display is having trouble.
- 30:16Yeah.
- 30:17But luckily it's still going.
- 30:18Yeah.
- 30:19I know.
- 30:19I switched to Linux two years ago and 99% of the time it works great.
- 30:23But of course on this podcast.
- 30:24Yeah.
- 30:25It's fine.
- 30:26It's all good.
- 30:27Murphy waits for the maximum pressure.
- 30:29Yeah.
- 30:30Maximum pain.
- 30:31It's a straight.
- 30:31Exactly.
- 30:32Let me just go through a couple here that I think would need.
- 30:37I have pulled them up.
- 30:38One of them was this active search because I feel like this is the type of thing that is
- 30:43like really easy, but also really calls out for some interesting JavaScript thing.
- 30:49So over here, you've got a page.
- 30:53You don't have the outer shell bits, right?
- 30:55Body.
- 30:55Yeah.
- 30:55But whatever.
- 30:56You don't need that, right?
- 30:58You've got a header that says what we're going to do is we're going to search.
- 31:02Yep.
- 31:02And then you have an HTMX indicator next to the title.
- 31:06Yep.
- 31:07Presumably when something's happening over an AJAX request, that thing spins.
- 31:10And then when it stops, it goes away.
- 31:12Is that what that means?
- 31:13Yeah.
- 31:13So the class HTMX indicator is a class that's dynamically indicated or excuse me, dynamically
- 31:20added to your webpage.
- 31:22And it allows you to start with an opacity of zero.
- 31:25And then when a class is added to it, it'll transition to an opacity of one.
- 31:32And so that's the best pattern that I found for having a request indicator.
- 31:35And one of the problems that you run into in all, you know, even normal web requests, browsers
- 31:41these days often don't do a very good job of notifying users something's happening, right?
- 31:46And so this is particularly a problem when AJAX is in play.
- 31:50There's no indicator to say, hey, something's going on.
- 31:53And so HTMX provides infrastructure for doing that sort of thing for you.
- 31:58And you don't have to do anything, right?
- 31:59Just having this thing exist.
- 32:01It knows, okay, if I'm doing a request somehow, some way, what's happening?
- 32:05You do have to call out the indicator that you want to show.
- 32:08Now, one thing I should say with attributes, they're typically inherited.
- 32:12So if you had one indicator that you wanted to show for all AJAX requests, for example,
- 32:16you could put the AJAX indicator attribute on the body of your web app.
- 32:22And then all AJAX requests would then use that because it's as with CSS, attributes are inherited
- 32:29and most attributes are inherited in HTMX.
- 32:33And so you can hoist attributes up the DOM and have them apply to multiple things.
- 32:39Fantastic.
- 32:40So you can avoid repeating yourself using that technique.
- 32:44Okay, cool.
- 32:45So we've got that little indicator there.
- 32:48And yeah, like you said, so you've got to indicate which indicator you want to use, but you don't
- 32:52have to trigger it.
- 32:53Exactly.
- 32:53Then you've got an input, like a text input, and it has a placeholder.
- 32:57It just says, please begin typing to search.
- 33:00It has a HX-post, which is slash search.
- 33:03Presumably it's posting the data of it as a form, right?
- 33:08Yeah, it's posting it.
- 33:09Yeah, exactly.
- 33:09It's posting it and including the, by default, if it's on an input, it'll include that input's value.
- 33:15Nice.
- 33:15And then it has a trigger.
- 33:17Yeah.
- 33:17So the trigger is key up.
- 33:19Yep.
- 33:19Changed.
- 33:20Yep.
- 33:20That's two things, right?
- 33:21Like, so if I command V it or like somehow like drag text into it or key up.
- 33:26So the either event, is that what that's saying?
- 33:28Changed is a little different.
- 33:30So key up is the event that we're responding to.
- 33:33And then change says only issue requests if the input value has changed.
- 33:37Got it.
- 33:38Okay.
- 33:38So if I somehow hit.
- 33:41So if you hit an arrow key, for example.
- 33:42Yeah.
- 33:43Yeah, exactly.
- 33:44Okay.
- 33:44Got it.
- 33:44Arrow key.
- 33:45The value doesn't change and you don't want to issue a request in that case.
- 33:49Yeah, that makes sense.
- 33:49The other thing you have is delay 500 milliseconds because, you know, it depends on what the event is.
- 33:56Like click it.
- 33:57It maybe doesn't matter, but like mouse move.
- 34:00You're going to get a lot of those events, right?
- 34:02You want to just wreck the server uselessly.
- 34:05You want to say, okay, like, did it just flash, flash, flash the screen?
- 34:08Like just wait till they've slowed down typing.
- 34:11Right, exactly.
- 34:12So this is called debouncing an input, right?
- 34:14You don't want to, on every event, you don't want to issue a request.
- 34:19That would be crazy and not a good user experience.
- 34:21And certainly it would be very hard on your server.
- 34:23And so what you can do is you can add a delay modifier to a trigger and say delay, wait until a key up.
- 34:32So if a key up occurs, wait 500 milliseconds.
- 34:35And if another key up occurs in that 500 milliseconds, don't issue the original request.
- 34:40So you effectively wait for the user to stop typing before you issue a request.
- 34:44And there's another option, which is a throttle, which might be more appropriate for mouse movements,
- 34:50where you say only issue a request every, you know, one, every second or something, according to mouse moves.
- 34:56Depends very much on what you're trying to accomplish with your UX.
- 34:59Those are two different techniques for it.
- 35:03This portion of Talk Python To Me is brought to you by YourBase.
- 35:07I'm excited to welcome YourBase as a new sponsor of Talk Python.
- 35:10YourBase has a really cool product that will dramatically improve testing and CI of your Python applications.
- 35:16If you could benefit from having pytest run your test 100 times faster or more, you need to check them out.
- 35:22Here's how it works.
- 35:23YourBase observes what tests interact with which part of your application code.
- 35:27And the first time you run it, the speed is roughly the same as normal.
- 35:30But the next time you run pytest is where the magic is.
- 35:34YourBase knows which parts of your application code has changed.
- 35:38If the code under test hasn't changed, why test it again?
- 35:41So YourBase only runs the tests that have interacted with the part of the code that has.
- 35:46If you change just a couple of functions, you only need to run the few relevant tests and all the others can be safely skipped.
- 35:53This means skipping hundreds or even thousands of tests most of the time,
- 35:57making your dev test workflow and your CI builds much, much faster.
- 36:02All you have to do is install YourBase and run pytest as usual.
- 36:06They'll take it from there.
- 36:07Get your free trial by visiting talkpython.fm/YourBase.
- 36:11YourBase test acceleration works with the tools you're already using.
- 36:15So give them a pip install and see the difference right away.
- 36:17Get started at talkpython.fm/YourBase.
- 36:21The final thing is to set the target, which is a CSS selector.
- 36:27So hash search results, which is the ID.
- 36:32And you've got a table with the search results and that's it.
- 36:35This is the, besides the server side that does the actual search response, this is the entire implementation of your dynamic search page, right?
- 36:43Yeah, that's right.
- 36:44So what is that?
- 36:45It looks like four attributes.
- 36:47You have four attributes to implement dynamic search or active search, I think is what Google terms it when you go to Google and start searching.
- 36:54And this is a great example of something I think many web apps would benefit from.
- 36:59And it can be achieved very quickly with just a small amount of HTMX on the front end and a small refactoring of the code you probably already have on the back end.
- 37:10Yeah.
- 37:10What I really like about this is if you've already implemented the search page to return a table of results, you've already written all this code.
- 37:17Yep.
- 37:17Everything is here.
- 37:19Like you have a form.
- 37:20You've submitted the form.
- 37:21You've got a response.
- 37:22You've rendered the table.
- 37:23You probably show the form again.
- 37:24Yeah.
- 37:25Although those things are present, you just can turn it to a on key down, key up rather.
- 37:31Yeah.
- 37:32Basically make it much nicer without almost any effort.
- 37:36Yeah, exactly.
- 37:36And again, I think this is showing how HTMX is taking HTML as a hypermedia and pushing it forward, right?
- 37:43This, you know, I think in an ideal world, this would just be part of HTML.
- 37:48It's just taking this hypermedia concept and saying, let's go further with it because HTML is kind of stalled as a hypermedia and they aren't doing much with it.
- 37:57So that's very much where HTMX is coming from.
- 38:00And that's the philosophical underpinning of the library.
- 38:04Yeah.
- 38:04Super cool.
- 38:05All right.
- 38:06So one of the things I love about your examples, one, this whole library has a rich set of examples.
- 38:13We'll go through two others.
- 38:15Sure.
- 38:15And, but one, the examples are there.
- 38:18They're clear.
- 38:19They're visual.
- 38:20And you have a live one right embedded in the page.
- 38:23I don't have to pull up like rebel or whatever to like go figure out, well, how's this really going to work?
- 38:28I can just go here.
- 38:29So if I want to see if there's a username, Michael, I just type, am I?
- 38:33No, but there are, there's a username, Molly with M I in the domain.
- 38:39And there's Jessamine, M I in her name and so on.
- 38:43Right.
- 38:44So that's amazing.
- 38:45Yeah.
- 38:45I've tried to focus on making things as visual as possible because I, you know, what I run into is people don't believe what you can accomplish with this library.
- 38:54And so I really wanted to make it jump out and say, hey, you know, yeah, there's stuff you can do in Vue.js that would be tough to do in HTMX or react, you know, react or whatever you're using for your front end.
- 39:07But nonetheless, there's a lot of stuff that would benefit a lot of web apps that can be done using this simpler model.
- 39:13And if you're able to, you know, the question is, is, is it good enough?
- 39:17And I think it is good enough for probably 90, 90, 90 plus percent of the websites that are out there.
- 39:22I mean, it certainly would improve, you know, the vast majority of websites that were out there, just a little bit of HTMX.
- 39:29Yeah.
- 39:29It reminds me of what jQuery did for the web.
- 39:32It doesn't remind me of jQuery, but jQuery for, I know probably a lot of people view jQuery negatively as like this sort of spaghetti code type of story these days.
- 39:42But when it came out, it was like, oh my gosh, I can sprinkle in a few things and this becomes really amazing.
- 39:49Yeah.
- 39:49Right.
- 39:49I get that feeling as well.
- 39:51It's like easy to add to something that exists.
- 39:53Yeah, that's right.
- 39:54And, you know, this whole thing, we came, I came out of the jQuery world just like you did.
- 39:58And so I think you're right that there's, with jQuery, there was always an incrementalist approach.
- 40:04You could add things incrementally.
- 40:06You didn't have to buy into a huge bit of infrastructure.
- 40:09It turned into spaghetti code in the long run.
- 40:11I agree with those criticisms of jQuery.
- 40:13And so hopefully with HTMX, because of the way it's built, you're not going to run into those same issues.
- 40:19I think there's some, conceptually there are reasons why that is.
- 40:22So with HTMX, you tend to put the actions on the thing that does the action.
- 40:27Whereas in jQuery, you would move things to a separate place.
- 40:31It would be over in some job.
- 40:32Right, like dollar document ready sort of thing.
- 40:34They would be living somewhere else.
- 40:36And that was kind of sold under this idea of separation of concerns, which is a design principle.
- 40:41for software.
- 40:42I've been trying to push this idea of locality of behavior, which is intention with separation of concerns.
- 40:49And the idea of locality of behavior is that you want to put the things that a code unit does in the code unit.
- 40:56So a button should say what it does.
- 40:58It should say, I issue a post to this URL, and then I do this with the response.
- 41:03And that's exactly what HTMX does.
- 41:05And again, that's in contrast with jQuery, where you would hook up a click handler in some other place, and you would just be staring at this button wondering why it was doing what it was doing.
- 41:15And so locality of behavior is what I'm trying to use as a terminology to describe this idea of putting stuff in line in the HTML to explain what this thing does.
- 41:25And there are other tools that are doing this as well that are getting popular.
- 41:29The two big ones are AlpineJS and Tailwind CSS.
- 41:34Both of those, you put your stuff in the HTML.
- 41:36And I think those two projects pair very well with HTMX in that you can kind of do everything right there in your HTML.
- 41:44It can be a little overwhelming at first if you're not used to that style of programming, but it has a lot of benefits associated with it.
- 41:50Yeah.
- 41:50I've never, I haven't even heard of AlpineJS, so I'm going to definitely have to check that out.
- 41:54But Tailwind I've heard of, and Tailwind's pretty interesting as well.
- 41:57It's like sort of a replacement for Bootstrap, but not in the same sort of abstract style.
- 42:02It's more like, say, like, you describe it as the way you want it to be.
- 42:06Like, I want the font to be medium.
- 42:07Yeah.
- 42:08Rather than say this is the main text, and the main text is formatted medium-sized, right?
- 42:13Yeah.
- 42:13Exactly.
- 42:14You inline things.
- 42:16So when you're looking at a button, you can see why it has rounded curves or why it has the padding that it has and so forth.
- 42:24I think people have started to recognize the separation of concerns, while certainly a good thing in some ways,
- 42:30and, you know, a valid design principle has some disadvantages.
- 42:33And the big one that I see is this sort of spooky action at a distance where someone can change a file somewhere else,
- 42:40and suddenly your button doesn't work anymore or whatever.
- 42:44Yeah.
- 42:44Yeah.
- 42:44Yeah.
- 42:44I think, well, the separation in this scenario is hx-post is slash search.
- 42:51Like, this describes exactly in the web sense of what a URI means to describe this is what I want this to be,
- 42:59but it doesn't describe the implementation.
- 43:01Right.
- 43:01Right.
- 43:02That lives in the server.
- 43:02Yep.
- 43:03And so I think there's an interesting philosophy there as well.
- 43:05Yeah.
- 43:05Yeah, there is.
- 43:06And it's really that restful, uniform interface idea from the early web.
- 43:13It's, you know, I keep saying this, but we're trying to take HTML and drive it forward as a hypertext.
- 43:19Give you more power as a hypertext developer.
- 43:22Yeah.
- 43:23Super cool.
- 43:24All right, let's take a few things from the live audience.
- 43:26So we got Nick says, I love that this supplements server-side frameworks like Django rather than trying to replace parts of them.
- 43:32Yeah.
- 43:33Yeah, absolutely.
- 43:34For sure.
- 43:34Alec has an interesting fix for your monitor.
- 43:37Okay.
- 43:37Tudo app install new monitor.
- 43:39Easy.
- 43:39Yeah.
- 43:40Since you're on Linux, right?
- 43:41If I could get a terminal to show, I've got my laptop monitor over here.
- 43:44I'm literally staring at a blank, at a black screen.
- 43:47It flickers every once in a while, so I get a brief view.
- 43:50Catch a quick view.
- 43:50I'm not touching anything.
- 43:52If it's recording.
- 43:53It's all good.
- 43:54It's working.
- 43:54And then Nick also says, now we need an hx-python tag to run arbitrary Python in the browser.
- 44:00Just kidding.
- 44:01Don't do that.
- 44:02With HTMX, I think that you've removed a lot of the pressure to have Python in the browser with HTMX.
- 44:08And so I was optimistic, you know, all jokes aside, I was optimistic when WebAssembly was first proposed that it would break the dominance of JavaScript in the browser.
- 44:18But my experience thus far, and I have to admit, I haven't looked at it in a while.
- 44:21Is that WebAssembly has been so low-level that it's probably not going to help.
- 44:29And maybe I can't tell if that was intentional or not.
- 44:31Yeah.
- 44:32But in my experience, there wasn't a good interop layer between the DOM and WebAssembly even.
- 44:39And so, okay.
- 44:41The vast majority of scripting I want to do is DOM related.
- 44:44Yeah.
- 44:45It's all about the DOM.
- 44:46So let me give you my WebAssembly sidebar here.
- 44:49And I'd love to hear your thoughts.
- 44:51I hear two problems with WebAssembly.
- 44:53One is this DOM story, right?
- 44:55Like, this could be fixed, right?
- 44:57WebAssembly could be evolved to have like a, like, and here's the DOM API.
- 45:01Right.
- 45:02In a real straightforward way.
- 45:03I know there's a lot of separation and whatnot, but I cannot believe that it couldn't be figured out.
- 45:08Yeah.
- 45:09Two, the problem I hear about this is, well, you can have Python in the browser and things like PyIodide have actually done this to like compile the C into WebAssembly, the CPython runtime and the scientific libraries into a WebAssembly thing.
- 45:26And then you can download it and you can do limited stuff.
- 45:28It's limited because of the limitations of the DOM, but you can still run Python in your browser.
- 45:32It just so happens it's a 10 meg download.
- 45:34Yeah.
- 45:35Right.
- 45:35Here's what I would love to see.
- 45:36I would love to see the major language providers, C++, Python, .NET.
- 45:41You just go down the list, Java, Rails, provide a WebAssembly thing against some API and every major browser just builds that in.
- 45:51So my Firefox comes with Python, Ruby, Java, and .NET.
- 45:56These are all like 10 or 20 meg binaries.
- 45:58Right.
- 45:59The world would be like, then that whole problem of, well, do you download it?
- 46:03What if you redownload?
- 46:04What if it's out of, like, just they ship JavaScript.
- 46:06Yeah.
- 46:06If all they had to do is include a host of other features as WebAssembly, like, the problem would be solved.
- 46:12But there's just a little too much friction along the way to make that happen, I think.
- 46:16Yeah.
- 46:16It really, the core problem there, I think, is the core libraries that, you know, that come with all these programming languages.
- 46:24It's one reason why Rust actually does pretty well with WebAssembly.
- 46:27It just doesn't come with very much.
- 46:29Yeah.
- 46:29And that's a reasonable solution.
- 46:31If I was super passionate about Python, I might look at just writing an interpreted, and it sounds like there might already be an interpreted version of Python in the browser.
- 46:41So, HyperScript, which is a scripting language that I'm working on as kind of a passion project that's loosely associated with HTMX, is a scripting language, and it works in the browser, and it's just interpreted.
- 46:52And JavaScript is so fast in the browser now that you can actually get away with it.
- 46:57So, as long as your Python wasn't, you know, trying to do scientific computing, you're just trying to do basic web scripting, you know, adding classes to DOM elements and so forth.
- 47:07You want to do Vue.js stuff like stuff, but you don't want to write.
- 47:10You want to create Python classes and then, like, hook Python functions.
- 47:14Yeah.
- 47:15Right?
- 47:15Yeah.
- 47:15That actually, you know, in my opinion, if I were going to take a look at that problem, I'd look at doing an interpreted language.
- 47:21Yeah.
- 47:21Interesting.
- 47:22There is Sculpt, which is pretty interesting, and this runs Python in the browser.
- 47:27So, like, the example on the homepage is like a little turtle on an HTML canvas.
- 47:31Okay.
- 47:31And this is all client-side.
- 47:33But it's, it's like close.
- 47:36It's not the same.
- 47:37Right.
- 47:37So, I mean, that's the same for all the languages.
- 47:40Yeah.
- 47:40All right.
- 47:40Let's go back to this example here, because I think there's still a lot of really good things we haven't even touched on.
- 47:45And we're, I mean, we're only on, what, four tags?
- 47:47Yeah.
- 47:47I know.
- 47:49So, we talked about this little example here.
- 47:51And as I'm typing, people can see the little searching.
- 47:54They go and type.
- 47:55They can see, like, in the H3, they can see the little searching bit.
- 47:58Yep.
- 47:58But all of these things, I think, are neat.
- 48:01But you kind of wonder, well, what's happening?
- 48:02Like, what's going on really?
- 48:04Like, especially if this is a server-side thing, what's the HTTP traffic with the server?
- 48:10And you added this little, like, built-in debuggery toolbar thing.
- 48:15It's not a debugger toolbar.
- 48:16It's a debugger footer.
- 48:17Yeah.
- 48:18A debug footer.
- 48:19Yeah.
- 48:19And as you interact with the examples, on every one of the examples, you can see, well, what is the initial traffic?
- 48:25What is sent over?
- 48:27And you click on it.
- 48:28It has a history of all the requests that they made.
- 48:31Yep.
- 48:31What was posted over and then what was returned from the server.
- 48:34Yep.
- 48:35And it's super clear.
- 48:37Yeah.
- 48:38Like, you can go to the last one.
- 48:39You can see exactly.
- 48:40This is what's on this, you know, up at the top.
- 48:42Yep.
- 48:42And you look at the bottom.
- 48:43Well, there's the TRTDs that make that happen.
- 48:45Yeah.
- 48:45Yeah.
- 48:46Yeah.
- 48:46Yeah.
- 48:46I really wanted to focus on the examples to drive home just how easy it was.
- 48:50And then also what you could accomplish with the library.
- 48:53Yeah.
- 48:54Quite cool.
- 48:56All right.
- 48:56Let's touch on a couple other examples.
- 48:58I pulled them up because I wanted to highlight them.
- 49:00Click to edit.
- 49:01Okay.
- 49:01Let's go look at click to edit.
- 49:02That's a pretty good one.
- 49:03Yep.
- 49:04Again, I apologize.
- 49:06I'm on my phone.
- 49:07Yeah.
- 49:07Yeah.
- 49:08Yeah.
- 49:08Yeah.
- 49:08No worries.
- 49:08So here what you've got is you've got a form and it's not form-like.
- 49:14It's like just static text with divs and spans and whatnot.
- 49:18So you've got first name is Joe, last name is Blow, email is such and such.
- 49:23And if you hit click to edit, those things all become, well, the values become text inputs.
- 49:30Yeah.
- 49:30I could make Joey Joe and hit submit and in place, it becomes Joey.
- 49:35That's right.
- 49:35That effect.
- 49:36This is a really cool example, right?
- 49:38Like instead of having forms everywhere, you can just have HTML and like a grid.
- 49:42And you could say, an example I would imagine maybe is a grid of responses.
- 49:47And then you want to edit one of the lines of the grid.
- 49:50Yep.
- 49:50Like I want to edit this entry and then boom, those all become drop down flex or they become
- 49:55date time pickers or whatever the heck you want to make them become.
- 49:58And then they go back, right?
- 50:00Yeah.
- 50:00Like an editable row concept.
- 50:02Yes, exactly.
- 50:03Yep.
- 50:03Yeah.
- 50:04Yeah.
- 50:04Super easy example of what's happening.
- 50:06If you click edit, it returns the form HTML text.
- 50:09When you submit it, it returns the div span version of it.
- 50:12Beautiful.
- 50:13Yeah, exactly.
- 50:14So, you know, probably not going to the details of all the attributes that make this happen,
- 50:19but there's an HX get to get the form.
- 50:22That form gets swapped in to that little element.
- 50:25You don't have a big page refresh.
- 50:27You don't go to some other URL and then you can click save and it just does a put.
- 50:31Put being the traditional way to update something or the standard way.
- 50:35Know the URL and you want to make a change to it instead of a post you do a put because
- 50:39that's restful.
- 50:39Yeah.
- 50:40Yeah, exactly.
- 50:40And so you use an HX put and then when that put succeeds, you would render just the row again.
- 50:46And if that put failed for validation reasons, for example, you would just render the form
- 50:51with the error messages in it.
- 50:52And this is very similar to the way you do standard, you know, web app development in the web 1.0
- 50:59model, but you've managed to bring down your target to just this little form.
- 51:03And so you don't have to do redirects and stuff like this anymore.
- 51:07Interesting.
- 51:07I hadn't really thought about the errors.
- 51:09Yeah, I hadn't thought about the error response.
- 51:12But for example, you could say return the form, but in your server side template, you could say,
- 51:18well, this one has an error.
- 51:19So what we're going to do is put an error message at the top and we're going to put an
- 51:23error has error attribute onto the form element, which will make it glow red or something
- 51:27like that.
- 51:28Exactly.
- 51:28And if you wanted, so one common thing to do is to, you have your error messages elsewhere,
- 51:34right?
- 51:35They're not down in that element.
- 51:36I like inline error messages myself, but a lot of people like to show errors at the top.
- 51:41And so HTML, HTMX, excuse me, has tools to do that.
- 51:44You can use what's called an out of band response.
- 51:47So you can have a content that is streamed down that specifies this is out of band content and
- 51:53it needs to go somewhere else in the DOM.
- 51:55Typically it uses an ID.
- 51:56And so you could use that to put an error message, you know, up on the header if you
- 52:01wanted to do that.
- 52:01Yeah.
- 52:02Another common way to do this one that I like, if you're going to have something like that
- 52:06is to have some sort of growl library where it kind of.
- 52:09Like a toast notification pop-up type of thing.
- 52:12Exactly.
- 52:13Something like that.
- 52:14And so for that, what you might use is the HTMX has some fairly well-developed response
- 52:19headers and one of them is HX trigger.
- 52:21And you can use that to trigger an event with an argument.
- 52:24The argument in this case would be the error message to show.
- 52:28And then you can write a little bit of code on the front end to listen for that custom event
- 52:33that you're triggering and then show toast message saying, hey, it's saved.
- 52:38Oh, that's cool.
- 52:38So there's a bunch of different tools in there depending on what you're trying to accomplish.
- 52:42Yeah.
- 52:43All right.
- 52:44Out in the live stream, Apar says, hey from San Francisco.
- 52:47Hey, welcome to the live stream.
- 52:49Nick comment.
- 52:50I'm curious how this compares to two-way binding with something like Vue.
- 52:54Is the DOM reactive with an underlying data model so that they stay in sync?
- 52:58The answer is no.
- 52:59So HTMX adopts the original model of the web, this RESTful model where hyper, you may have
- 53:07heard at some point in your programming career, the acronym HADEOUS.
- 53:11It's a bad acronym, particularly these days.
- 53:13But the acronym stands for hypermedia or hypertext as the engine of application state.
- 53:19And so there is no backing model on the client side.
- 53:22Rather, the model, the source of truth is the back end and the front end just sits there
- 53:28and reacts to user inputs.
- 53:31And whenever a user input occurs that needs to trigger a state change, a request is issued
- 53:36to the server and then the updated state of that resource is returned via HTML.
- 53:41Yeah.
- 53:42And it kind of flows through this interaction.
- 53:44That's right.
- 53:45Right.
- 53:45So let me give you an example.
- 53:46So in this click to edit thing, when I click edit on the button, it knows it's on slash
- 53:51context, contact slash one.
- 53:53And I click the edit.
- 53:54What comes back is a form and has HX dash put with slash contact slash one as the action.
- 54:01Right.
- 54:02So then when I submit it, it flows that it was row one or item one I was editing on over.
- 54:07And then when it comes back, the response is, well, now it has the contact slash one slash
- 54:14edit in that URL.
- 54:15So it kind of flows.
- 54:16Yeah.
- 54:17This is actually super hideous.
- 54:18There's many things that you find in these APIs and people adopting REST.
- 54:23They're like, oh, we're going to take all the REST principles except for this hypermedia
- 54:26as application state.
- 54:27That we don't really care about.
- 54:28But this, the more you talk about it, it really is.
- 54:31Yeah.
- 54:31Well, it is.
- 54:32It's because people, this is a long conversation, but holy smokes, I've been arguing with people
- 54:36on the internet about this for a while.
- 54:38I don't think REST makes any sense when you talk about JSON because it does to some extent.
- 54:44The HTTP verbs make sense.
- 54:45Yeah, they do.
- 54:46That's about it.
- 54:47Other than that, right?
- 54:48There's a lot more to this whole REST.
- 54:50Maybe the representation, maybe the URL layout in some cases makes sense.
- 54:54Yeah.
- 54:54But when Fielding wrote his, Roy Fielding is where the term, his dissertation at University
- 55:00of California, Irvine is where all this terminology comes out of.
- 55:04And what he wrote, he was describing the web.
- 55:07He was describing HTML.
- 55:08He was describing the way Web 1.0 worked with that.
- 55:13And a big focus on that was this idea of stateless HTML and hypertext as the engine of application
- 55:19state.
- 55:20That being one of the crux issues within the section that's about what's called the uniform
- 55:26interface.
- 55:26We don't want you to get too much into the details of that right now.
- 55:29I'd be happy to talk about that maybe offline later, maybe in a different context.
- 55:35But when you're in JSON, hypertext isn't the engine of application state.
- 55:40There's a client-side model that is your application state.
- 55:43And now you're in a stateful world.
- 55:45And you're in some ways much closer to what thick apps used to look like back in the 90s
- 55:50than you are to the original web model.
- 55:52It's a different model and there are advantages and disadvantages to it.
- 55:56I like it a lot.
- 55:57I think there's a lot of power to it.
- 55:58And so, you know, to make a long story short, no, there's no reactive aspect here.
- 56:04The DOM is the source of truth.
- 56:06The server is really the source of truth.
- 56:08But the DOM, as far as the user is aware, is the source of truth.
- 56:11And it's stateless, just like the original web model.
- 56:14Right.
- 56:14The view model is super nice.
- 56:16I mean, you create these little JavaScript classes and they just kind of build up their
- 56:19data.
- 56:20And it's really cool.
- 56:21And it binds with the DOM.
- 56:22But like, what if someone refreshes the page?
- 56:24Right.
- 56:25Or something like that, right?
- 56:26Yeah.
- 56:26Oh my gosh.
- 56:27It's a God.
- 56:28Oh no.
- 56:29Right.
- 56:29So yeah, there could be drawbacks as well.
- 56:31Reactivity is, you know, sometimes I can be a little too hard, I think, on just the nature
- 56:37of the internet.
- 56:38But, you know, reactivity, this notion of a reactive two-way binding, that's new.
- 56:43It's relatively new.
- 56:45There were UI toolkits that did something, did similar stuff, but not as deeply as the current
- 56:50set do.
- 56:51And so there's something new there and it is useful in a lot of ways.
- 56:55But for a lot of apps, it's overkill and there are disadvantages that are associated
- 57:00with it.
- 57:00Sinking the two models is difficult.
- 57:02And if you let your DOM be the source of truth, the server be the source of truth and your
- 57:08DOM be a stateless representation of it, then there's a huge number of advantages that come
- 57:12along with that.
- 57:13Yeah, that's for sure.
- 57:14Like if you have the same page open on multiple tabs, for example, like the database is still
- 57:19in sync on the server.
- 57:19Yeah.
- 57:20All right.
- 57:20Let's look at one more example.
- 57:21Sure.
- 57:21And we'll do a little bit of wrap up.
- 57:24I'm a little hesitant to show this to people because I kind of hate this, but it's also
- 57:27a very neat infinite scroll.
- 57:30Infinite scroll can also be implemented as click to load.
- 57:33So I too am ambivalent towards this pattern, but it's so common.
- 57:39What I don't like about it is it's super hard to share it with somebody.
- 57:44They say, okay, go to this part of the search result.
- 57:46Like, well, where is it?
- 57:48Like, well, keep scrolling down.
- 57:49No, like hold down the page.
- 57:51You know what I mean?
- 57:52It's just like hard to share or to get back to you.
- 57:54Anyway, it's a lot.
- 57:55I don't know.
- 57:56But infinite scroll is neat.
- 57:57And so here you've got a table row that says hx-get slash context slash page equals to
- 58:04our question mark page equals to is a query string.
- 58:07And then hx trigger is revealed.
- 58:09This is like as you scroll down, when it becomes revealed within the DOM, run this.
- 58:14And then swap after end.
- 58:16Yeah.
- 58:17I guess.
- 58:17What's that mean?
- 58:18After end.
- 58:19So what that means is so you would put this code on the last row, the last result of your
- 58:25page of results.
- 58:26And so what that's going to do is it's going to issue a request to the server.
- 58:31And then when it gets that content back, it's going to append it after the end of this element,
- 58:36the element that this is on this table row.
- 58:38And so that new content, which is presumably going to be a new series of rows, is going to
- 58:44get appended after the last row.
- 58:47And so that's how you get that next set of rows.
- 58:50And then on the last row of that, there would be, again, this when I'm revealed.
- 58:55The response will come back with an hx-get on it, right?
- 58:58Yeah.
- 58:58So it'll come back with the hx on it, and it'll just keep going down the line until finally you
- 59:03get to a point where you don't have any more.
- 59:04And so you don't bother encoding one of these revealed triggers.
- 59:09And that would just be the end of it.
- 59:11So I agree with you.
- 59:12As you are, I am ambivalent towards this.
- 59:16I tend to prefer paging for exactly the reasons you talk about.
- 59:19And I should note that there is an attribute called hxpush.
- 59:23Is it hx?
- 59:25hxpush URL, excuse me, that will push the URL of the request up into the browser's history,
- 59:33like into the URL.
- 59:34Okay.
- 59:35And add it to the history.
- 59:37So you can use the back button and all that.
- 59:39And it does all that kind of automagically for you.
- 59:42Does it allow deep linking?
- 59:43Yeah, yeah.
- 59:45Now, that being said, if that URL, you know, someone can copy and paste into a new
- 59:49tab, for example.
- 59:50And so you have to handle both the HTMX request to that URL, as well as the normal non-HTMX
- 59:58request to that URL.
- 59:59And those might be very different.
- 1:00:00Yeah.
- 1:00:00But if you did that, then it would support potentially deep linking into this sort of experience.
- 1:00:06Exactly.
- 1:00:06And so, and then I just finished that thought.
- 1:00:09There's a header that comes in when it's an HTMX request, hx requests true.
- 1:00:15And so you can check that header and say, okay, this wasn't an HTMX request.
- 1:00:20So I need to render the entire surrounding for this thing.
- 1:00:23Or, oh, it was an HTMX request.
- 1:00:25So I just need to render this partial.
- 1:00:27And that's a very common pattern to have a little if statement on a URL that needs to service both
- 1:00:32of these to check the header value.
- 1:00:33Oh, that's pretty cool.
- 1:00:34Yeah.
- 1:00:34Nice.
- 1:00:35Okay.
- 1:00:35So let's see.
- 1:00:37Let me, I'm going to do it.
- 1:00:38I'm going to scroll here.
- 1:00:39Yeah.
- 1:00:39Here we go.
- 1:00:39There you go.
- 1:00:40See the indicator and down comes some more.
- 1:00:42Yeah.
- 1:00:42Oh, fantastic.
- 1:00:43Yeah.
- 1:00:43Yeah.
- 1:00:44There we go.
- 1:00:44And you can obviously, you know, pull up the little debug butter.
- 1:00:47Yeah.
- 1:00:48And see those behaviors here, which is great.
- 1:00:51Yeah.
- 1:00:51And again, the backend agnostic.
- 1:00:52So just, this could just be normal Python on the backend.
- 1:00:55Nothing fancy.
- 1:00:56Yeah.
- 1:00:56Django, Flask, or Rails.
- 1:00:58Take your pick.
- 1:00:58Yep.
- 1:00:59Whatever you like.
- 1:01:00I mean, it could, I've been bagging on Node because I'm not a huge fan of it as a platform that I want
- 1:01:05to work on, but it could also be Node, right?
- 1:01:07Sure.
- 1:01:07Like if people are out there doing that, it could be.
- 1:01:09Yeah.
- 1:01:09Hypertext on whatever you'd like.
- 1:01:11Howl.
- 1:01:12Howl.
- 1:01:13Yeah.
- 1:01:14All right.
- 1:01:14So let me wrap this up with a little bit of concreteness here.
- 1:01:17Sure.
- 1:01:17So tell us really quickly about, there was Intercooler and now it's HTMX.
- 1:01:23Just real quickly.
- 1:01:23What is the story with this transition?
- 1:01:25Yeah.
- 1:01:26So I created Intercooler, which is the predecessor to HTMX.
- 1:01:29HTMX is basically Intercooler 2.0.
- 1:01:31And then I created Intercooler back in 2013, I believe.
- 1:01:35And it was, again, I came out of the jQuery world.
- 1:01:38And so it started off basically as a jQuery plugin.
- 1:01:41And it grew to the point that I felt like, okay, I'm going to create a separate library
- 1:01:45for this.
- 1:01:46And last year when COVID hit, it had always had in the back of my mind that I didn't like
- 1:01:51the jQuery dependency in Intercooler.
- 1:01:53And so I just, you know, everyone was kind of at home.
- 1:01:57And in order to avoid losing my mind, I said, well, I wonder if I could pull the jQuery
- 1:02:05dependency out Intercooler.
- 1:02:07And it turned out JavaScript's come a long way.
- 1:02:10And I was able to do it pretty quickly.
- 1:02:12And so as I was doing that, one other thing that I thought about, I really, you know, I
- 1:02:17learned a lot as I built Intercooler.js.
- 1:02:19And I developed a much firmer sort of theoretical basis for it.
- 1:02:23It's like, okay, we're really, we're trying to drive HTML forward.
- 1:02:26And one thing that had always annoyed me about Intercooler.js was that it was compared with,
- 1:02:32you know, Angular was the big one when it was first out.
- 1:02:36And then eventually React and then, and Vue.js.
- 1:02:39And because it had that JS in the name.
- 1:02:41And so there was, people would treat it as a JavaScript library rather than thinking of
- 1:02:46it in these more hypertext oriented terms.
- 1:02:49And I was astounded to find out that HTMX org was available in 2020.
- 1:02:54And, but it was.
- 1:02:56And so I grabbed it and I was like, this is a great name.
- 1:02:58I originally called it something else, but came to my senses and said, you know, HTMX really
- 1:03:02captures this.
- 1:03:03We're trying to extend HTML.
- 1:03:05So HTMX.
- 1:03:06It's short.
- 1:03:07It's available as a domain name and it captures what you're after.
- 1:03:10Yeah.
- 1:03:11Yeah.
- 1:03:11So it worked out very well.
- 1:03:13So I'm very happy with it.
- 1:03:14Let me round out our conversation with a concrete example here for this.
- 1:03:18So people might wonder like, where is this being used out in the world?
- 1:03:21Right.
- 1:03:21And I'm obviously, I think it makes a ton of sense, especially in these little like backend
- 1:03:26internal corporate apps that don't get a ton of love, but could really benefit from this.
- 1:03:30But there's also some popular ones like realpython.com out there is one of the most
- 1:03:35popular ones, Python websites out there run by my good friend, Dan Bader.
- 1:03:40Cool.
- 1:03:40And I was just talking to Dan saying, I'm going to talk to you, Carson.
- 1:03:43He's like, oh, I love this.
- 1:03:44I actually use intercooler on the site.
- 1:03:46Okay, cool.
- 1:03:46So if you go over to the quizzes section, you can pull up one of these quizzes and you
- 1:03:51hit start.
- 1:03:52These sort of like test your knowledge things.
- 1:03:53So here it says like, for example, in Python three, the maximum value for an integer is
- 1:03:57two to the 63rd minus one.
- 1:03:58Oh, that's so false.
- 1:03:59And you click on it, it like reveals the check answer of the thing.
- 1:04:04And then you go to the next question or you can expand the explanation.
- 1:04:08How would you express a five, the base 16 integer?
- 1:04:12I have no idea.
- 1:04:12All right.
- 1:04:13Not the point.
- 1:04:14Not the point.
- 1:04:15But this thing, this experience of going through these, these steps with the progress bar, because
- 1:04:20there's a cool progress bar in HTMX and all that stuff.
- 1:04:23Yeah.
- 1:04:24Like this is a cool use case of that type of situation.
- 1:04:27That's really nice and easy to do.
- 1:04:29Yeah.
- 1:04:29And there's a huge amount of code that's written out there, even in apps that are more dramatic
- 1:04:33and need, need this reactive infrastructure in places, there are probably places within the
- 1:04:39app where that's not necessary.
- 1:04:40So, you know, one common thing I'll say is, okay, maybe HTMX doesn't apply to your entire
- 1:04:45app.
- 1:04:45Maybe you're doing concurrent editing of rich, you know, using canvas or something crazy like
- 1:04:51that.
- 1:04:51All right, fine.
- 1:04:52But you probably have a settings page for that app.
- 1:04:55And that settings page is going to be fairly standard forms.
- 1:04:59And that's something where maybe rather than using whatever reactive component you're using
- 1:05:04to manage the really complicated state, you could tear all that out, save that complexity
- 1:05:09budget and just use HTMX just to sync with the server for your, for your settings page,
- 1:05:14you know, but that even, you know, how many react, how many crazy apps do we use day to day?
- 1:05:18For the most part I use, you know, I go and I read blog posts, maybe I check my email
- 1:05:24and so forth.
- 1:05:24And a lot of those apps could be improved pretty dramatically by just using some basic
- 1:05:29HTMX patterns without adding a huge amount of complexity.
- 1:05:32Yeah, I totally agree.
- 1:05:33Totally agree.
- 1:05:34All right, Carson, I think we're pretty much out of time.
- 1:05:37Okay.
- 1:05:37But let me always ask two questions at the end of the show.
- 1:05:42Sure.
- 1:05:42Two questions.
- 1:05:42So I'll hit with them before we close it out.
- 1:05:45If you're going to work on HTMX or do some other programming, what editor do you use these
- 1:05:49days?
- 1:05:50I use WebStorm.
- 1:05:51WebStorm, right on.
- 1:05:53Yeah, I'm JetBrains.
- 1:05:55Yeah, go ahead.
- 1:05:55I'm a JetBrains guy.
- 1:05:56Yeah, same here.
- 1:05:57I'm a big fan of PyCharm and basically the web side of its functionality is just WebStorm
- 1:06:01as well, which is very cool.
- 1:06:03It's super nice.
- 1:06:03I encourage people to pay for their tools.
- 1:06:06If you're a programmer, spend some money.
- 1:06:09I mean, they have stuff for free, but they, they do tremendous work.
- 1:06:12I know that what's the Microsoft editor has become very popular.
- 1:06:16VS Code.
- 1:06:17Yeah.
- 1:06:17Yeah.
- 1:06:17But I don't know.
- 1:06:18It is what it is.
- 1:06:20You know, it's a holy war situation.
- 1:06:21So don't take me too seriously on this.
- 1:06:24But if you're willing to listen to me, if you're willing to listen to a random guy on
- 1:06:28the internet to at least take a look at the JetBrains stuff.
- 1:06:32I like your idea of, you know, support and encourage the things that you want to see
- 1:06:36more of.
- 1:06:37Right.
- 1:06:37For sure.
- 1:06:38And then normally I ask for like a Python library that people are really interested in.
- 1:06:42But in this, this case, let's, how about a JavaScript library or CSS library or something
- 1:06:46like that, that you think people should really check out like something on npm or tailwind
- 1:06:51or whatever.
- 1:06:52Yeah.
- 1:06:52I like, I think looking at tailwinds and looking at Alpine JS, if I may, we didn't really get
- 1:06:57a chance to talk about it, but Hyperscript is a scripting language.
- 1:07:01It's kind of a natural language, scripting language for the front end, very front end
- 1:07:05focused.
- 1:07:05That's kind of got some interesting aspects to it.
- 1:07:08But I think, you know, rather than recommending one particular library, I'd say just that this
- 1:07:14idea of locality of behavior, looking for libraries where you're putting the code in the code unit
- 1:07:20rather than having a bunch of different places.
- 1:07:22And so tailwinds and Alpine JS are two that jump out at me in addition to HTMX as being worth
- 1:07:27taking a look at.
- 1:07:28I know there's a lot of Django people that are using that combination and are very passionate
- 1:07:32about it.
- 1:07:33Yeah.
- 1:07:33Fantastic.
- 1:07:34Yeah.
- 1:07:34I know some people certainly passionate about it as well.
- 1:07:36Nick out of the live stream says, view single file components, violate the separation concerns
- 1:07:41and lead towards this locality that you talk about as well.
- 1:07:44Yeah.
- 1:07:44It's a great improvement.
- 1:07:45Yeah.
- 1:07:45I think front end components are kind of moved that way as well.
- 1:07:48That's exactly right.
- 1:07:49Now, you know, do I, that's, that comes with a lot of other stuff that I don't think is necessary
- 1:07:54for a lot of web apps, but there's just this move, I think.
- 1:07:57And so I'm trying to use again, locality of behavior.
- 1:07:59And I've got an essay up on htmx.org slash talk.
- 1:08:04You can look, there's a locality of behavior essay where I'm trying to push that term and
- 1:08:08get people to adopt it when they're trying to explain to people why, Hey, why are you
- 1:08:11inlining all this code?
- 1:08:13Cause you know, they're like, Oh, this is the worst idea.
- 1:08:15No, you can't.
- 1:08:17And it's like, well, you can.
- 1:08:18And most people and people are actually having experiencing productivity and maintenance
- 1:08:23increase, you know, increases when they do it.
- 1:08:26So.
- 1:08:26Yeah.
- 1:08:27I like your idea of the spooky action at a distance.
- 1:08:29Right.
- 1:08:30A little quantum mechanics in there.
- 1:08:31Yep.
- 1:08:32Cool.
- 1:08:33All right.
- 1:08:34Final call to action.
- 1:08:35People are psyched about htmx.
- 1:08:37Maybe they're psyched about not doing too much JavaScript on the front end.
- 1:08:41What do you tell them?
- 1:08:41Well, check out htmx.org.
- 1:08:44Please start the GitHub repository.
- 1:08:45That is my primary source of compensation for, for htmx at this point.
- 1:08:51And, you know, we have a discord server that you can jump on as well.
- 1:08:55If you have questions, Twitter is getting more active.
- 1:08:57If you follow htmx, there's htmx.org on Twitter, which I run and it's getting more and more active,
- 1:09:05but the discord is friendly at this point.
- 1:09:07And, so I encourage people who are interested in this to jump on there and ask questions.
- 1:09:11There's a lot of people that understand the library very well and,
- 1:09:15know a lot of different backends because htmx is backend agnostic.
- 1:09:19Kind of each backend needs its own sort of expert to help out with it.
- 1:09:24And so, you know, hopefully in a few years, we built up a good set of example libraries,
- 1:09:28but at this point, if that's not available, then the discord is probably the best place to check out.
- 1:09:34Okay.
- 1:09:34Fantastic.
- 1:09:35Well, thanks again for being here and thanks for creating this.
- 1:09:38A lot of nice comments in the live stream as well saying, thanks for creating it.
- 1:09:42So yeah, I think you're onto something here and I'm happy to share with people.
- 1:09:45Hopefully it can superpower some of these Django flask, et cetera, apps without replacing them.
- 1:09:50Yeah, I really, and I appreciate again, you, you know, taking something that's obviously outside the,
- 1:09:55the normal Python world and, giving me a chance to talk to people about it because I do think it will
- 1:10:00help people stay in Python longer before they, they feel like they have to abandon it for JavaScript.
- 1:10:07Yeah.
- 1:10:07We can remove some JavaScript guilt.
- 1:10:09Yep.
- 1:10:09Exactly.
- 1:10:10Not doing the front and front.
- 1:10:11That's right.
- 1:10:11It's okay.
- 1:10:12Awesome.
- 1:10:12It's okay.
- 1:10:13You don't have to use JavaScript for everything.
- 1:10:15It's true.
- 1:10:17All right.
- 1:10:17Thanks again.
- 1:10:18See you later.
- 1:10:19Have a good one.
- 1:10:19Bye-bye.
- 1:10:20Bye.
- 1:10:20This has been another episode of talk Python to me.
- 1:10:24Our guest on this episode was Carson from big sky software, and it's been brought to you by
- 1:10:28Sentry, your base and assembly AI.
- 1:10:31Take some stress out of your life.
- 1:10:33Get notified immediately about errors in your web applications with Sentry.
- 1:10:37Just visit talkpython.fm/sentry and get started for free and use the promo code
- 1:10:42talkpython2021.
- 1:10:44When you sign up, your base test acceleration will dramatically improve dev test workflows and
- 1:10:51CI builds of your Python applications.
- 1:10:53If you could benefit from having pytest run your tests a hundred times faster or more, you
- 1:10:57need to check them out.
- 1:10:58Get started at talkpython.fm/your base.
- 1:11:01Transcripts for this and all of our episodes are brought to you by assembly AI.
- 1:11:06Do you need a great automatic speech to text API?
- 1:11:09Get human level accuracy in just a few lines of code.
- 1:11:11Visit talkpython.fm/assembly AI.
- 1:11:14Want to level up your Python?
- 1:11:16We have one of the largest catalogs of Python video courses over at talk Python.
- 1:11:20Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:11:25And best of all, there's not a subscription in sight.
- 1:11:28Check it out for yourself at training.talkpython.fm.
- 1:11:31Be sure to subscribe to the show.
- 1:11:32Open your favorite podcast app and search for Python.
- 1:11:35We should be right at the top.
- 1:11:37You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the
- 1:11:42direct RSS feed at /rss on talkpython.fm.
- 1:11:47We're live streaming most of our recordings these days.
- 1:11:49If you want to be part of the show and have your comments featured on the air, be sure to
- 1:11:53subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:11:57This is your host, Michael Kennedy.
- 1:11:59Thanks so much for listening.
- 1:12:00I really appreciate it.
- 1:12:02Now get out there and write some Python code.
- 1:12:03I'll see you next time.