viewflow / django-material

Material Design for Django
http://viewflow.io/
BSD 3-Clause "New" or "Revised" License
2.49k stars 425 forks source link

BUG: django_textinput.html and django_numberinput.html not found in templates/material/fields #495

Closed DanielSwain closed 3 years ago

DanielSwain commented 3 years ago

Environment (dev machine): Python 3.8 Django 2.2 venv manager: pipenv

The above two templates were not found. In each case, I created the files by making a copy of django_input.html, and then the page came up fine. Is this a bug?

kmmbvnr commented 3 years ago

i can't reproduce.

(venv) kmmbvnr@sparkle:/tmp/tmp.R4Q1ipDB3R$ pip install django-material
Collecting django-material
  Downloading https://files.pythonhosted.org/packages/fd/cf/497805e44805dc12aa8ab25751a88073b118ad8f74774d3262cbe69812c9/django_material-1.7.4-py2.py3-none-any.whl (6.7MB)
    100% |████████████████████████████████| 6.7MB 142kB/s 
Collecting six (from django-material)
  Cache entry deserialization failed, entry ignored
  Using cached https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl
Installing collected packages: six, django-material
Successfully installed django-material-1.7.4 six-1.15.0
(venv) kmmbvnr@sparkle:/tmp/tmp.R4Q1ipDB3R$ ls venv/lib/python3.6/site-packages/material/templates/material/fields/
django_checkboxinput.html           django_input.html                   django_selectmultiple.html
django_checkboxselectmultiple.html  django_nullbooleanselect.html       django_splitdatetimewidget.html
django_clearablefileinput.html      django_radioselect.html             django_textarea.html
django_dateinput.html               _django_rangeinput.html             django_timeinput.html
django_datetimeinput.html           django_selectdatewidget.html        
django_fileinput.html               django_select.html                  
(venv) kmmbvnr@sparkle:/tmp/tmp.R4Q1ipDB3R$ ls venv/lib/python3.6/site-packages/material/templates/material/fields/django_input.html 
venv/lib/python3.6/site-packages/material/templates/material/fields/django_input.html

Could you ensure that you have included 'material' package into your INSTALLED_APPS

DanielSwain commented 3 years ago

Yes, material is in INSTALLED_APPS. This is a website that's been working for a couple of years in Python 2.7/Django 1.11 that I am now working to upgrade to Python 3.8/Django 2.2. I searched the repo for django_textinput.html and django_numberinput.html (and even for django_input.html) and nothing was found, so without delving into the code I assume that the template names are being constructed somewhere in the code.

In the material/fields directory in my venv at this point, I have the following in order to get things working (after having created django_textinput.html and django_numberinput.html as stated in my first comment above):

.                          django_checkboxselectmultiple.html  django_fileinput.html          django_radioselect.html       django_splitdatetimewidget.html
..                         django_clearablefileinput.html      django_input.html              django_select.html            django_textarea.html
_django_rangeinput.html    django_dateinput.html               django_nullbooleanselect.html  django_selectdatewidget.html  django_textinput.html
django_checkboxinput.html  django_datetimeinput.html           django_numberinput.html        django_selectmultiple.html    django_timeinput.html

In settings.TEMPLATES I have the following (note the DIRS and loaders sections):

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            THEME_PATH,
        ],
        # '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',
            ],
            'loaders': [
                # Directories loader must come first
                'django.template.loaders.app_directories.Loader',
                'django.template.loaders.filesystem.Loader',
            ],
        },
    },
]

If I remove the django_textinput.html file, I then get the following error (project-specific names changed, and note that the error message at the bottom is reached after it has exhausted looking for the component's template in both the app directories and then the THEME_PATH): NOTE: I tried moving material below crispy_forms, and the error still comes up.

Django Version: 2.2.18
Python Version: 3.8.5
Installed Applications:
['material',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'adminsortable2',
 'crispy_forms',
...]

Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Template error:
In template /opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/templates/material/layout/row.html, error at line 2
   20
   1 : {% load material_form_internal %}
   2 : <div class="layout-row row">{% for element, span in parent.container_12 %}<div class="col s12 m{{ span }}"> {% render element %} {% endrender %}</div>{% endfor %}</div>
   3 : 

Traceback:

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/core/handlers/exception.py" in inner
  34.             response = get_response(request)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/core/handlers/base.py" in _get_response
  145.                 response = self.process_exception_by_middleware(e, request)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/core/handlers/base.py" in _get_response
  143.                 response = response.render()

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/response.py" in render
  106.             self.content = self.rendered_content

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/response.py" in rendered_content
  83.         content = template.render(context, self._request)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  171.                     return self._render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in _render
  163.         return self.nodelist.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in _render
  163.         return self.nodelist.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/loader_tags.py" in render
  150.             return compiled_parent._render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in _render
  163.         return self.nodelist.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/loader_tags.py" in render
  62.                 result = block.nodelist.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/defaulttags.py" in render
  309.                 return nodelist.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/templatetags/material_form.py" in render
  142.             return template.render(context_flatten(context))

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  171.                     return self._render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in _render
  163.         return self.nodelist.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/templatetags/material_form.py" in render
  203.         value = self.nodelist.render(context).strip()

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/defaulttags.py" in render
  309.                 return nodelist.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/templatetags/material_form.py" in render
  203.         value = self.nodelist.render(context).strip()

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/templatetags/material_form_internal.py" in render
  92.                 return element.render(context, **options)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/base.py" in render
  53.             return template.render(context.flatten())

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  171.                     return self._render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in _render
  163.         return self.nodelist.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/defaulttags.py" in render
  209.                     nodelist.append(node.render_annotated(context))

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/templatetags/material_form_internal.py" in render
  92.                 return element.render(context, **options)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/base.py" in render
  53.             return template.render(context.flatten())

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  171.                     return self._render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in _render
  163.         return self.nodelist.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/defaulttags.py" in render
  209.                     nodelist.append(node.render_annotated(context))

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/templatetags/material_form_internal.py" in render
  92.                 return element.render(context, **options)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/base.py" in render
  53.             return template.render(context.flatten())

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/backends/django.py" in render
  61.             return self.template.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  171.                     return self._render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in _render
  163.         return self.nodelist.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render
  937.                 bit = node.render_annotated(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/defaulttags.py" in render
  209.                     nodelist.append(node.render_annotated(context))

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/base.py" in render_annotated
  904.             return self.render(context)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/templatetags/material_form_internal.py" in render
  92.                 return element.render(context, **options)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/base.py" in render
  210.                 template = _get_field_template(

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/material/base.py" in _get_field_template
  93.     return select_template(template_names)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/loader.py" in select_template
  42.                 return engine.get_template(template_name)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/backends/django.py" in get_template
  34.             return Template(self.engine.get_template(template_name), self)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/engine.py" in get_template
  143.         template, origin = self.find_template(template_name)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/engine.py" in find_template
  125.                 template = loader.get_template(name, skip=skip)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/loaders/base.py" in get_template
  24.                 contents = self.get_contents(origin)

File "/opt/virtualenvs/MY_VIRTUAL_ENV/lib/python3.8/site-packages/django/template/loaders/filesystem.py" in get_contents
  23.             with open(origin.name, encoding=self.engine.file_charset) as fp:

Exception Type: NotADirectoryError at /my-previously-working-url/
  Exception Value: [Errno 20] Not a directory: '/THEME_PATH/material/fields/django_textinput.html'

The same error occurs if I remove the django_numberinput.html file. It's only happening for these two items, but that could be related to the types of fields declared in the form. I haven't tried submitting the form yet (see below), so I don't even know if these two contrived templates will even work upon submission. Any suggestions you could offer are very much appreciated.

Afterword - ignore if not related to the above: Not to diverge here, but I haven't tried submitting the form yet because I'm also getting an error on a call to formSelect() when the page loads. I doubt that it's related, but here's that error in case it is somehow related to the above. As you can see, there are two <select> elements that are found leading up to the call to formSelect(). The weird thing is that materialize.js (where I think formSelect is declared) is being loaded fine (last screenshot).

image

materialize.js is being loaded fine, and it even comes up when I go to http://mysite/static/material/js/materialize.js.

image

kmmbvnr commented 3 years ago

unfortunately i can't reproduces the issue.

I hope the reference project and docs, woud help you analyze what settings in your code caused the issue.

http://docs.viewflow.io/material_forms.html

https://gitlab.com/-/snippets/2077186