Django template file organization

at first

Nice to meet you, this is koki1992. This is the first post. I look forward to working with you. I'm a student now, and from next year I'm planning to jump into an industry that has nothing to do with programming. The class was canceled due to the spread of Covid-19, and I had some time left, so I started Quita.

About organizing Django template files

When you create a Django template, in that app's folder,

mkdir templates/<App name>/

I think that you will create a folder and save the template in this. However, as the number of templates increases, I think that one folder will contain dozens of template files.

In this case, even if you name the template neatly, it will be difficult to reach the target template file, which can be frustrating.

Separate folders within the template folder

So, in my case, when the application grows to a certain extent, I try to divide the template files into folders within the template folder.

Concrete example

I am making an app for organizing my information, and I will show you the template structure of that app. Although it is a configuration

In an app called NOTE

I made the element. There is a Note in the Binder, a Page in the Note, and a Block in the Page.

Each element has a template for new creation, update, and deletion in addition to the template displayed by that element.

That's why it became like this.

├── templates
│   └── NOTE
│       ├── Binder
│       │   ├── Binders.html
│       │   ├── CreateBinder.html
│       │   ├── DeleteBinder.html
│       │   └── UpdateBinder.html
│       ├── Block
│       │   ├── Blocks.html
│       │   ├── CreateBlock.html
│       │   ├── DeleteBlock.html
│       │   └── UpdateBlock.html
│       ├── Note
│       │   ├── CreateNote.html
│       │   ├── DeleteNote.html
│       │   ├── Notes.html
│       │   └── UpdateNote.html
│       └── Page
│           ├── CreatePage.html
│           ├── DeletePage.html
│           ├── Pages.html
│           └── UpdatePage.html

It's organized and much easier to read than just digging the template files into the template folder without thinking about it.

Finally

Thank you for watching until the end. I'm still an amateur, but I'd like to manage to gather information on the internet and improve my skills. I would like to write an article about the knowledge gained in the process. We look forward to your opinions and impressions.

I also started Twitter. If you don't mind, please follow me.

Recommended Posts

Django template file organization
Django # 2 (template)
Django HTML Template # 2
Django Template notes
Django HTML template
Django Template Tips
(Note) Template file search order in Django
File upload with django
Template registration from Django Bootstrap
Show Django ManyToManyField in Template
Use jinja2 template in excel file
Django
Django static file (static) related settings summary
Make a filter with a django template
template
Create a file uploader with Django
How to do arithmetic with Django template
WEB application development using Django [Template addition]
(For myself) Django_1 (Basic / Hello World / Template)
Resolve Angural JS and Django template conflicts
Write a short if-else for Django Template
Django template reads Makdown and reStructuredText written in an external file as HTML