Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#15525 closed Bug (fixed)

Custom template tags loading breaks whenever templatetags is a python file

Reported by: the_drow Owned by: the_drow
Component: Template system Version: 1.2
Severity: Normal Keywords: templatetags
Cc: omer.drow@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: UI/UX:

Description

Steps to recreate:
1) Create a django application.
2) Create an app.
3) In the app, instead of a templatetags folder create a templatetags.py.
4) Try to load it in the view.

The error:
'module' object has no attribute 'path'

Now, I know I shouldn't be doing that (But didn't know when I did it and it drove me nuts) but shouldn't this at least throw a less cryptic error message?

Attachments (1)

module_loading.patch (763 bytes) - added by traff 4 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 Changed 4 years ago by the_drow

  • Cc omer.drow@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

Changed 4 years ago by traff

comment:3 Changed 4 years ago by traff

  • Has patch set

comment:4 Changed 4 years ago by the_drow

  • Patch needs improvement set

Please improve the error to something along the lines of: "Unable to load template tags. templatetags must be a module but templatetags.py was probably found in %app_name%"

comment:5 Changed 4 years ago by jezdez

  • Needs tests set

comment:6 Changed 4 years ago by the_drow

  • Owner changed from nobody to the_drow
  • Status changed from new to assigned

Recreated the traceback in order to add a more specific error:

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.2.5
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.admin',
 'django.contrib.sites',
 'django.contrib.flatpages',
 'dojango',
 'south',
 'reversion',
 'sitetree',
 'tagging',
 'paging',
 'disqus',
 'autoslug',
 'django_generic_flatblocks',
 'cms',
 'blog',
 'testtemplatetagserror']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'dojango.middleware.DojoCollector',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware')


Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
  100.                     response = callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/views/generic/simple.py" in direct_to_template
  17.     t = loader.get_template(template)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in get_template
  157.     template, origin = find_template(template_name)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in find_template
  134.             source, display_name = loader(name, dirs)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in __call__
  42.         return self.load_template(template_name, template_dirs)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in load_template
  48.             template = get_template_from_string(source, origin, template_name)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader.py" in get_template_from_string
  168.     return Template(source, origin, name)
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in __init__
  158.         self.nodelist = compile_string(template_string, origin)
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in compile_string
  186.     return parser.parse()
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in parse
  282.                     compiled_result = compile_func(self, token)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in do_extends
  195.     nodelist = parser.parse()
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in parse
  282.                     compiled_result = compile_func(self, token)
File "/usr/local/lib/python2.6/dist-packages/django/template/loader_tags.py" in do_block
  173.     nodelist = parser.parse(('endblock', 'endblock %s' % block_name))
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in parse
  282.                     compiled_result = compile_func(self, token)
File "/usr/local/lib/python2.6/dist-packages/django/template/defaulttags.py" in load
  924.             lib = get_library(taglib)
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in get_library
  1040.             lib = import_library(taglib_module)
File "/usr/local/lib/python2.6/dist-packages/django/template/__init__.py" in import_library
  992.         if not module_has_submodule(app_module, taglib):
File "/usr/local/lib/python2.6/dist-packages/django/utils/module_loading.py" in module_has_submodule
  17.     for entry in package.__path__:  # No __path__, then not a package.

Exception Type: AttributeError at /
Exception Value: 'module' object has no attribute '__path__'

Why does it break on:

    nodelist = parser.parse(('endblock', 'endblock %s' % block_name))

And where does the try block begins and ends?

comment:7 Changed 4 years ago by lrekucki

  • Severity set to Normal
  • Type set to Bug

comment:8 Changed 4 years ago by SmileyChris

  • Resolution set to fixed
  • Status changed from assigned to closed

In [16703]:

Fixed #15525 -- Custom template tags loading breaks whenever templatetags is a python file

comment:9 Changed 4 years ago by jacob

  • milestone 1.4 deleted

Milestone 1.4 deleted

Note: See TracTickets for help on using tickets.
Back to Top