Skip to content

error PatternLibraryEmpty  #116

Closed
@alstormyk

Description

@alstormyk

I can't seem to get this working in a Django app or a Wagtail app. I'm getting...

Internal Server Error: /pattern-library/ Traceback (most recent call last): File "/home/arashi/.cache/pypoetry/virtualenvs/portfolio-Iy91sLkC-py3.8/lib64/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/home/arashi/.cache/pypoetry/virtualenvs/portfolio-Iy91sLkC-py3.8/lib64/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/home/arashi/.cache/pypoetry/virtualenvs/portfolio-Iy91sLkC-py3.8/lib64/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/arashi/.cache/pypoetry/virtualenvs/portfolio-Iy91sLkC-py3.8/lib64/python3.8/site-packages/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, **kwargs) File "/home/arashi/.cache/pypoetry/virtualenvs/portfolio-Iy91sLkC-py3.8/lib64/python3.8/site-packages/django/views/generic/base.py", line 97, in dispatch return handler(request, *args, **kwargs) File "/home/arashi/.cache/pypoetry/virtualenvs/portfolio-Iy91sLkC-py3.8/lib64/python3.8/site-packages/pattern_library/views.py", line 43, in get pattern_template_name = self.get_first_template(templates) File "/home/arashi/.cache/pypoetry/virtualenvs/portfolio-Iy91sLkC-py3.8/lib64/python3.8/site-packages/pattern_library/views.py", line 31, in get_first_template raise PatternLibraryEmpty( pattern_library.exceptions.PatternLibraryEmpty: No templates found in the pattern library at '/home/arashi/snow/Websites/Django/portfolio/project_styleguide/templates'
The templates are working for the project as a whole, but I can't go to /pattern-library/ . I get the error
PatternLibraryEmpty at /pattern-library/

Activity

bcdickinson

bcdickinson commented on Sep 26, 2020

@bcdickinson

I appreciate this was a while ago, sorry for the slow response. This error means that there are no templates in the locations that that pattern library expects to find them.

Could you tell me:

  • Which version you were using?
  • The layout of your templates on the filesystem?
  • The settings you were using at the time?
mazenshanti

mazenshanti commented on Oct 13, 2020

@mazenshanti

Hi @bcdickinson,
I may have the same problem:
PatternLibraryEmpty at /pattern-library/
No templates found matching: '(('atoms', ['patterns/atoms']), ('molecules', ['patterns/molecules']), ('organisms', ['patterns/organisms']), ('templates', ['patterns/templates']), ('pages', ['patterns/pages']))'

requirements.txt:
Django==3.1
django-pattern-library==0.2.9
wagtail==2.10.2

base.py:

PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

INSTALLED_APPS = [
    'home',
    'search',
    'pattern_library',

    'wagtail.contrib.forms',
    'wagtail.contrib.redirects',
    'wagtail.embeds',
    'wagtail.sites',
    'wagtail.users',
    'wagtail.snippets',
    'wagtail.documents',
    'wagtail.images',
    'wagtail.search',
    'wagtail.admin',
    'wagtail.core',

    'modelcluster',
    'taggit',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        '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',
            ],
            'builtins': ['pattern_library.loader_tags'],
        },
    },
]

PATTERN_LIBRARY_TEMPLATE_PREFIX = "patterns"
PATTERN_LIBRARY_TEMPLATE_SUFFIX = ".html"
PATTERN_LIBRARY_TEMPLATE_DIR = os.path.join(PROJECT_DIR, 'templates')

structure:
.
├── manage.py
├── test
│   ├── init.py
│   ├── settings
│   │   ├── init.py
│   │   ├── base.py
│   │   ├── dev.py
│   │   └── production.py
│   ├── static
│   │   ├── css
│   │   │   └── test.css
│   │   └── js
│   │   └── test.js
│   ├── templates
│   │   ├── 404.html
│   │   ├── 500.html
│   │   ├── base.html
│   │   └── patterns
│   │   ├── atoms
│   │   │   ├── tags_test_atom
│   │   │   │   ├── tags_test_atom.html
│   │   │   │   └── tags_test_atom.yaml
│   ├── urls.py
│   └── wsgi.py
├── requirements.txt

I'm looking forward to use your tool and the Atomic methodology, thanks.

allcaps

allcaps commented on Oct 13, 2020

@allcaps

Note that PATTERN_LIBRARY_TEMPLATE_DIR must be available for template loaders.
-- https://github.com/torchbox/django-pattern-library#how-to-install

Your test app is not in INSTALLED_APPS.

mazenshanti

mazenshanti commented on Oct 13, 2020

@mazenshanti

I tried to add another app and it works fine, @allcaps thanks.

  • I don't know why the main app "test" not added by default like "home", "search" in wagtail. However thanks a lot.
allcaps

allcaps commented on Oct 14, 2020

@allcaps

Tests directory is project config code and not an 'app'. Equivalent to the output of 'django-admin startproject tests' However, any folder that contains an init can be a Django app. So adding this directory to installed apps let's Django discover the templates.

Project layouts are always a bit opinionated. :)

I'd like to keep templates in apps, instead of one global template folder. @bcdickinson Does that make sense with PL? App loader templates in multiple locations?

bcdickinson

bcdickinson commented on Oct 14, 2020

@bcdickinson

@allcaps the need to put patterns in a single directory is going to be removed in an upcoming release, this PR sheds a bit more light on it: #124

added this to the Nice to have milestone on Nov 2, 2020
thibaudcolas

thibaudcolas commented on May 20, 2021

@thibaudcolas
Member

I will close this now as I believe our most recent release will likely have helped with this. The pattern library now supports crawling all apps’ templates, and soon will also support DIRS templates (#145).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @thibaudcolas@allcaps@mazenshanti@bcdickinson@alstormyk

      Issue actions

        error PatternLibraryEmpty · Issue #116 · torchbox/django-pattern-library