Wrong app name in template path?

My project has two apps, Catalog and Artwork.

In trying to resolve the url http://127.0.0.1:8000/artwork/public/drawings/, I get the error TemplateDoesNotExist at /artwork/public/drawings/ (artwork/group.html) .

The error page shows it’s trying to load …akdb-env/akdb/catalog/templates/artwork/group.html rather than …akdb-env/akdb/artwork/templates/artwork/group.html

The TEMPLATES setting is:

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',
                'catalog.context_processors.external_images_url',
           ],
        },
    },
]

And the INSTALLED_APPS setting is:

INSTALLED_APPS = [
    'catalog.apps.CatalogConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

Can you please clarify:

Describe the directory structure of your project.

What directory is the intended template in?

What does the render statement look like?

Directory structure, starting from the project dir:

akdb
├── akdb
├──── urls.py
├── artwork
├──── templates
├────── artwork
├──────── group.html ← this is the target template
├──────── <some other templates>
├──── urls.py
├──  catalog
├──── templates
├────── catalog
├──────── <some templates>
├──── urls.py

Render statement in artwork/views.py:

return render(request, "artwork/group.html", context)

So I don’t know where the artwork app is getting ‘catalog’ for the template path… but note that artwork/views.py does this import:

from catalog.models import Artwork, Group, Space

because the artwork app uses those same models as defined in the catalog app.

I don’t see where you have an artwork app listed in your INSTALLED_APPS setting. Is it there? (It’s searching your catalog app because it is listed.)

I thought of that, but, if I add the artwork app to INSTALLED_APPS, I get the error django.contrib.admin.exceptions.AlreadyRegistered: The model Artwork is already registered in app 'catalog'.

The artwork app works fine with this:

INSTALLED_APPS = [
    'catalog.apps.CatalogConfig',

but the catalog app fails with this:

INSTALLED_APPS = [
    'catalog.apps.CatalogConfig',
    'artwork.apps.ArtworkConfig',

What do your apps.py files look like? Also, please post the complete error message you are receiving, along with identifying when you are receiving it. (I think this error can also be caused by having the same model defined in two different admin.py files. Verify that this is not the case.)

They were identical… looks like that was the problem.

from django.contrib import admin
from catalog.models import Artwork, Group, Space, Status

admin.site.register(Artwork)
admin.site.register(Status)
admin.site.register(Group)
admin.site.register(Space)

Both apps use all the same models (so far); I removed them from the artwork admin.py and the error is gone. I’d guess that that file doesn’t even need to exist.

Sorry, that was the admin.py file(s), which seem to have been the problem. The apps.py files look right:

from django.apps import AppConfig

class CatalogConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'catalog'

and

from django.apps import AppConfig

class ArtworkConfig(AppConfig):
    default_auto_field = 'django.db.models.BigAutoField'
    name = 'artwork'