VeryApt / django-phone-field

Lightweight model and form field for phone numbers in Django
GNU General Public License v3.0
52 stars 13 forks source link

New to Django: TemplateDoesNotExist #12

Closed MBfromOK closed 4 years ago

MBfromOK commented 4 years ago

TemplateDoesNotExist at /admin/person/person/add/

phone_field/phone_widget.html

Request Method: GET
Request URL: http://127.0.0.1:8000/admin/person/person/add/
Django Version: 3.0.5
Exception Type: TemplateDoesNotExist
Exception Value: phone_field/phone_widget.html
Exception Location: D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\backends\django.py in reraise, line 84
Python Executable: D:\Dev\VSCode\Projects\Portal\env\Scripts\python.exe
Python Version: 3.7.7
Python Path: [
- 'D:\\Dev\\VSCode\\Projects\\Portal\\src', 
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\Scripts\\python37.zip',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\DLLs',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\lib',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\Scripts',
- 'C:\\DevSDKs\\Python\\Python37\\Lib',
- 'C:\\DevSDKs\\Python\\Python37\\DLLs',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\lib\\site-packages',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\lib\\site-packages\\odf',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\lib\\site-packages\\odf',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\lib\\site-packages\\odf',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\lib\\site-packages\\odf',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\lib\\site-packages\\odf',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\lib\\site-packages\\odf',
- 'D:\\Dev\\VSCode\\Projects\\Portal\\env\\lib\\site-packages\\odf'
]
MBfromOK commented 4 years ago

Realized I didn't send the actual traceback:

Traceback:

TemplateDoesNotExist at /admin/person/person/add/ by Django Environment:

Request Method: GET Request URL: http://127.0.0.1:8000/admin/person/person/add/

Django Version: 3.0.5 Python Version: 3.7.7 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'import_export', 'person'] 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 loader postmortem Django tried loading these templates, in this order:

Using engine django:

Template error: In template D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\contrib\admin\templates\admin\includes\fieldset.html, error at line 19 phone_field/phone_widget.html 9 : {% for field in line %} 10 : <div{% if not line.fields|length_is:'1' %} class="fieldBox{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} errors{% endif %}{% if field.field.is_hidden %} hidden{% endif %}"{% elif field.is_checkbox %} class="checkbox-row"{% endif %}> 11 : {% if not line.fields|length_is:'1' and not field.is_readonly %}{{ field.errors }}{% endif %} 12 : {% if field.is_checkbox %} 13 : {{ field.field }}{{ field.label_tag }} 14 : {% else %} 15 : {{ field.label_tag }} 16 : {% if field.is_readonly %} 17 :

{{ field.contents }}
18 : {% else %} 19 : {{ field.field }} 20 : {% endif %} 21 : {% endif %} 22 : {% if field.field.help_text %} 23 :
{{ field.field.help_text|safe }}
24 : {% endif %} 25 :
26 : {% endfor %} 27 :
28 : {% endfor %} 29 :

Traceback (most recent call last): File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\backends\django.py", line 34, in get_template return Template(self.engine.get_template(template_name), self) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\engine.py", line 143, in get_template template, origin = self.find_template(template_name) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\engine.py", line 129, in find_template raise TemplateDoesNotExist(name, tried=tried)

The above exception (phone_field/phone_widget.html) was the direct cause of the following exception: File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\backends\django.py", line 61, in render return self.template.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 171, in render return self._render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 163, in _render return self.nodelist.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 936, in render bit = node.render_annotated(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\loader_tags.py", line 150, in render return compiled_parent._render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 163, in _render return self.nodelist.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 936, in render bit = node.render_annotated(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\loader_tags.py", line 150, in render return compiled_parent._render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 163, in _render return self.nodelist.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 936, in render bit = node.render_annotated(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\loader_tags.py", line 62, in render result = block.nodelist.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 936, in render bit = node.render_annotated(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\loader_tags.py", line 62, in render result = block.nodelist.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 936, in render bit = node.render_annotated(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\defaulttags.py", line 209, in render nodelist.append(node.render_annotated(context)) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\loader_tags.py", line 188, in render return template.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 173, in render return self._render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 163, in _render return self.nodelist.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 936, in render bit = node.render_annotated(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\defaulttags.py", line 209, in render nodelist.append(node.render_annotated(context)) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\defaulttags.py", line 209, in render nodelist.append(node.render_annotated(context)) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\defaulttags.py", line 309, in render return nodelist.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 936, in render bit = node.render_annotated(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\defaulttags.py", line 309, in render return nodelist.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 936, in render bit = node.render_annotated(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 903, in render_annotated return self.render(context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 992, in render return render_value_in_context(output, context) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\base.py", line 971, in render_value_in_context value = str(value) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\utils\html.py", line 373, in klass.str = lambda self: mark_safe(klass_str(self)) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\forms\boundfield.py", line 33, in str return self.as_widget() File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\forms\boundfield.py", line 96, in as_widget renderer=self.form.renderer, File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\forms\widgets.py", line 242, in render return self._render(self.template_name, context, renderer) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\forms\widgets.py", line 247, in _render return mark_safe(renderer.render(template_name, context)) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\forms\renderers.py", line 30, in render template = self.get_template(template_name) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\forms\renderers.py", line 36, in get_template return self.engine.get_template(template_name) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\backends\django.py", line 36, in get_template reraise(exc, self) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\backends\django.py", line 84, in reraise raise new from exc

The above exception (phone_field/phone_widget.html) was the direct cause of the following exception: File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\core\handlers\exception.py", line 34, in inner response = get_response(request) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\core\handlers\base.py", line 145, in _get_response response = self.process_exception_by_middleware(e, request) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\core\handlers\base.py", line 143, in _get_response response = response.render() File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\response.py", line 105, in render self.content = self.rendered_content File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\response.py", line 83, in rendered_content return template.render(context, self._request) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\backends\django.py", line 63, in render reraise(exc, self.backend) File "D:\Dev\VSCode\Projects\Portal\env\lib\site-packages\django\template\backends\django.py", line 84, in reraise raise new from exc

Exception Type: TemplateDoesNotExist at /admin/person/person/add/ Exception Value: phone_field/phone_widget.html

MBfromOK commented 4 years ago

Could it be related to the solution found here: Django TemplateDoesNotExist?

That Solution:

chown -R www-data:www-data /usr/lib/python2.5/site-packages/projectname/*

If so, how would I do that in my non-server dev environment?

va-andrew commented 4 years ago

Hi,

I'd check your Django config:

MBfromOK commented 4 years ago

I am betting this is my fault; my app worked until I converted my phone number TextField to your phone_field...

Things I tried: I made migrations, migrated, and then deleted the db and started over. Upgraded to Python 3.8.2 64bit and 32bit I am running my project in a venv and I pip installed while the env was activated... Seems to work until I try to render the view.

INSTALLED_APPS:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'phone_field',
    'products',
    'pages',
]

TEMPLATES:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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',
            ],
        },
    },
]

let me know if you need more / different information.

As I said, I am guessing your app is fine... Thanks for whatever help you provide!

va-andrew commented 4 years ago
  1. Try setting 'DIRS': [], in your TEMPLATES setting so it is only relying on app dirs
  2. Create a new Django project altogether django-admin startproject testproj and putting in the bare minimum (a simple model with a phone_field field and an admin or template view).
MBfromOK commented 4 years ago

There was something not setting correctly... again, probably something I did... Build a completely new project directory and then copy pasted my files back. Works like a dream!

Zain-ali0 commented 2 years ago

i have same issues , and i try every solution without results , please if anyone can help me