TemplateDoesNotExist

I’m getting TemplateDoesNotExist error when I have the homepage in core(app)/templates/core/homepage.html

TemplateDoesNotExist at /
homepage.html
Template-loader postmortem
Django tried loading these templates, in this order:

Using engine django:

django.template.loaders.app_directories.Loader: D:\Portfolio\env\lib\site-packages\django\contrib\admin\templates\homepage.html (Source does not exist)
django.template.loaders.app_directories.Loader: D:\Portfolio\env\lib\site-packages\django\contrib\auth\templates\homepage.html (Source does not exist)
django.template.loaders.app_directories.Loader: D:\Portfolio\core\templates\homepage.html (Source does not exist)

It’s searching in core/templates/homepage.html when it’s in core/templates/core/homepage.html

I have also registered core as an app in the INSTALLED_APPS variable

We probably need to see the TEMPLATES settings from your settings.py file.

TEMPLATES = [

    {

        'BACKEND': 'django.template.backends.django.DjangoTemplates',

        'DIRS': [],

        'APP_DIRS': True,

        'OPTIONS': {

            'context_processors': [

                'django.template.context_processors.debug',

                'django.template.context_processors.request',

                'django.contrib.auth.context_processors.auth',

                'django.contrib.messages.context_processors.messages',

            ],

        },

    },

]

Ok, how/where are you referencing the template? Please show us the portion of the view where this template is being used.

from django.shortcuts import render

from django.views.generic import TemplateView

# Create your views here.

class HomePageView(TemplateView):

    template_name = "core/homepage.html"

I fixed it, I needed to add core/

I’m a bit confused right now, Where do I put my home page? Do I need to use the app core or what is the Django home page convention?

You put your home page wherever you want to put it, as long as your view and your TEMPLATES configuration agree on where they should be found.

I don’t know about any real “convention”. I know that we create a templates directory in the project directory.
Example:

project_dir
  app1
  app2
  static
  templates

We then add an entry to the DIRS entry of the TEMPLATES setting:
'DIRS': [ 'templates' ],
Every template used across multiple apps are located there. This includes our base template which is extended by just about every other template in the system.

Alright but, Do we put unique templates which is used by specific apps in the templates folder in the root directory like suppose core app uses home_page.html, and should it be located in projectdir/templates/core/home_page.html?

If I’m creating a Portfolio website with some JavaScript and CSS, How would you do the app naming and how would the directory tree look? (I couldn’t find anything regarding this)

In principle, your “home page” is still generally extending your “base” template. In many cases, a “home page” is your “base” template, with none of the blocks replaced by app-specific content - in which case your home page may reside in the top-level templates directory.

JavaScript and CSS are “static” files, not templates and are managed completely differently.

If you work your way through either (or both) of the official Django tutorial and Django Girls tutorial, you’ll see a common pattern used. I’d suggest following that until you learn enough to recognize when you need to do something different, at which point you’ll probably know what you want to do.
(It’s the same pattern used by the startproject and startapp commands.)

I’m a member of the “don’t create apps unnecessarily” camp. Unless you know you’re going to have components that should be isolated or are definitely going to be reused across different projects, I’d suggest staying with one app. You do avoid some potential problems that way.

Alright, Is it possible for you to link some open-source Github repositories so I can learn how they organize their apps and templates?

Sorry, I have no repos to identify. You could start by looking at Django itself, and maybe some of the more prominent Django based packages such as Wagtail or DjangoCMS or Django Rest Framework.

Alright, Thank you. I’ll look into it!

I will add that for most of this, it’s not an issue of “right” or “wrong”, it’s a question of “what works for you organizationally“. When you’re starting out on a project, you’ve got 83,247 things to worry about - this shouldn’t be one of them. Go with what makes sense to you.