jazzband / django-hosts

Dynamic and static host resolving for Django. Maps hostnames to URLconfs.
http://django-hosts.rtfd.org
Other
982 stars 106 forks source link

django 3.0 Incompatibility - "Invalid template library specified. ImportError raised when trying to load 'django_hosts.templatetags.hosts': cannot import name 'six' from 'django.utils'" #105

Closed patrickohemeng closed 4 years ago

patrickohemeng commented 4 years ago

I upgraded to Django 3.0 and on runserver this error is thrown

django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'django_hosts.templatetags.hosts': cannot import name 'six' from 'django.utils' (/Users/OHEMENGTUTU/Dropbox/Asoriba/TECH/CODEBASE/AsoribaAPI/lib/python3.7/site-packages/django/utils/init.py)

I think it has to do with Django 3.0 dropping dependency "six"

jar3b commented 4 years ago

Same error for me after upgrade to Django 3.0.

Possible solutions are:

  1. Use import six instead of from django.utils import six in resolvers.py and templatetags/hosts.py
  2. Use failback imports for these six imports
  3. Switch to using direct implementation of six.iteritems(**kw) - this is .items(), but if you do this, you will loose python2 support.

Also, after fixing this issue, new problem was arrived - import error for django.utils.lru_cache.lru_cache in resolvers.py. Solution may be similar to previous - fixing import to from functools import lru_cache (due to changes described in official django 3.0 release notes

Removed private Python 2 compatibility APIs
...
django.utils.lru_cache.lru_cache() - Alias of functools.lru_cache().
...

)

For myself i choose the second solution (failback imports) but i don't sure if that's a best decision. But if so, i can provide a PR.

Upd: similar issue - #98 and PR for it - #100 from @Djailla

idrishmakda52 commented 4 years ago

thank you using 1 answer it works

timgraham commented 4 years ago

duplicate of https://github.com/jazzband/django-hosts/issues/98

Virsail commented 3 years ago

same error