I know that you're supposed to have a templates folder within each app folder, how I have two questions clarify further. 1, Should I have 2 base.html files (one in each app) that are identical? This seems like it's creating more files than need be... and 2. What about the static and media folders? Should I also have two of each or should they be at the project and app folders level?
If there is supposed to be a static folder in each app folder then do I have two css files? I feel like that makes no sense since the css can cover things that overlap from app to app.
I'm also wondering if have it setup the way I currently have it will effect anything, or if "best practice" is more so just for if you're working on a project with multiple people (which I'm not, in which case should I care?)
Here is my current structure:
/evverest/
/evverest/
/feed/
/users/
/blog/
/templates/
/base/
/feed/
/users/
/static/
/css/
/media/
/post_pics/
/profile_pics/
Django comes with six built-in apps that we can examine.
Django root directory is the default app which Django provides you. It contains the files which will be used in maintaining the whole project. The name of Django root directory is the same as the project name you mentioned in django-admin startproject [projectname].
As mentioned, Django follows the MVT framework for architecture. MVT is generally very similar to that of MVC which is a Model, View, and Controller. The difference between MVC and MVT here is the Django itself does the work done by the controller part in the MVC architecture.
This can be a little bit confusing. I like to do this:
templates/
folder. This should include base.html
and any other templates from other plugins that you're overriding.templates/
folder inside the app, e.g. blog/templates/blog/blog_index.html
. These templates should {% extend 'base.html' %}
so that all apps in the project are using the same base template, which is in the global templates folder.STATIC_ROOT
folder from your Django settings, which I've called assets
below. I'd stick to using the one folder for simplicity.Here's an example of how this would look:
./evverest
├── evverest/
├── feed/
│ ├── templates/feed/feed_index.html
│ └── models.py
├── users/
│ ├── templates/users/users_index.html
│ └── models.py
├── templates/
│ └── base.html
├── static/
│ └── css/main.css
└── manage.py
For more on best practices, check out cookiecutter-django
. There's quite a lot to learn, but they're interested in following best practices, so it's a great resource.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With