Skip to content

error PatternLibraryEmpty #116

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
alstormyk opened this issue Jul 8, 2020 · 7 comments · May be fixed by #244
Closed

error PatternLibraryEmpty #116

alstormyk opened this issue Jul 8, 2020 · 7 comments · May be fixed by #244
Milestone

Comments

@alstormyk
Copy link

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/

@bcdickinson
Copy link

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
Copy link

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
Copy link

allcaps commented Oct 13, 2020

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
Copy link

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
Copy link

allcaps commented Oct 14, 2020

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
Copy link

@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

@thibaudcolas thibaudcolas added this to the Nice to have milestone Nov 2, 2020
@thibaudcolas
Copy link
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).

reedjones added a commit to reedjones/django-pattern-library that referenced this issue Mar 7, 2024
This commit modifies the django-pattern-library to use pathlib.Path for template paths. This ensures that the paths are handled consistently across different operating systems, including Windows.
The following functions have been modified to use pathlib.Path:
path_to_section()
section_for()
get_template_dirs()
get_pattern_config_str()
get_pattern_markdown()
Additionally, the TemplateRenderer.get_pattern_templates() method has been updated to use pathlib.Path for template paths.
possibly related issue: torchbox#116
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants