HTMX + Django: Modern Python Web Apps, Hold the JavaScript Transcripts
Chapter: Surveying the non-JS-enabled Django app
Lecture: Project directory structure

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The structure of VideoCollector is typical of a Django project. The project's name is VideoCollector, and that weird design decision from the Django
0:09 folks to have the configuration directory named the same as the project is present here. Inside the config directory you have the usual files.
0:18 In this course you'll be leaving the ASGI and WSGI files alone, as they're for putting
0:24 your project in production and I'll be sticking with the development server.
0:29 .py file is where you set Django's configuration. There are a few things that need to be changed
0:34 from their default values, particularly getting static files and template files configured.
0:39 I'll touch on those changes shortly, but the sample base project has those changes made already
0:44 if you're using it. Since the video collector project is small, I've been lazy and haven't
0:50 subdivided my URLs into sections, so all the pages in the site - yep, all four of them - are
0:56 configured in your I'll review the route declarations with you before the end of this lesson.
1:03 As you can guess from the presence of db.sqlite3, I'm using SQLite to store all of the data.
1:12 You'll recall that static files are things like javascript, images, and css - files that are used
1:19 by your web pages that don't require the template engine. As I'm a little cdn adverse - nothing like
1:25 your site falling over because some CDN somewhere decided to stop hosting the file you need,
1:30 I've downloaded fontawesome.htmx and other things to be served here.
1:34 The CSS directory contains a couple of style files. The JavaScript directory contains bootstrap's
1:41 JavaScript files and eventually will also contain the HTMLX JavaScript file.
1:46 The image directory contains the category banner images. A more advanced version of the site would
1:53 allow you to upload those, but to keep it simple, adding a category means needing to change the code a tiny bit. And now for the rest of the code.
2:02 The logic for our project, that's fun to say, is in a Django app called ""content"". I'm horrible at naming the main app.
2:12 Utility apps that do things, no problem, but I never know what to call the central one.
2:16 I used to call it ""core"", but somebody pointed out there is a Django core and that's confusing.
2:21 I tried main for a while, but that implies it's the entry point like in a script, which it isn't, so here I'm calling it content.
2:29 With only 4 webpages, this app isn't terribly large. The data structure model files are in the usual file, while the functions
2:38 that are the views for the 4 pages are in I won't be demoing it here, but has been written, so if you want to go and tinker
2:48 with the data directly, the admin models for each of the data models does exist.
2:52 The database file has been included in the git repo, so you don't need the fixture here,
2:58 but if you did want to start from scratch or had a strong desire to use a different database,
3:03 you could run the load data management command against this fixture to populate your database.
3:09 As I mentioned in lesson 2, this is a sister course for a Flask equivalent.
3:15 I stole Michael's data from the Flask version so I didn't have to create my own,
3:19 and there's a custom management command in here to feed the database from his JSON.
3:23 As you've got the fixture, you won't need it, but I left it there in case you're curious.
3:28 Every Django developer I've ever talked to has a different opinion on whether a template should
3:33 go with the app or not. I know that half of you watching this will be cranky with my decision.
3:39 Try to be forgiving. Generally, I only tend to put templates with an app if the app is one that
3:45 that I plan on being removable or is very self-contained. Otherwise, I use a single templates directory.
3:51 I find it easier to search for things this way, but understand that other coders do this differently. The templates directory has a base file
4:00 that all other files extend, containing the usual HTML boilerplate and a bunch of the bootstrap stuff. The other four files correspond
4:09 to the four pages of the site.

Talk Python's Mastodon Michael Kennedy's Mastodon