Hey Guys,
I'm using Django.js for a lot of my personal project. It's a great package and thanks for this amazing work !
On the new django's version (it seems to be fine until 1.7), I've got this error when I try to load the init.js file:
AttributeError at /djangojs/init.js
'module' object has no attribute 'urlpatterns'
Request Method: GET
Request URL: http://localhost:8000/djangojs/init.js
Django Version: 1.7
Exception Type: AttributeError
Exception Value:
'module' object has no attribute 'urlpatterns'
In order to make it worked, I had to change the _get_urls function in the urls_serializer file.
I test if the module contains an urlpatterns attributes if not I create a new tuple.
def _get_urls(module, prefix='', namespace=None):
urls = {}
if isinstance(module, (six.text_type, six.string_types)):
try:
__import__(module)
root_urls = sys.modules[module]
if hasattr(module, 'urlpatterns'):
patterns = module.urlpatterns
else:
patterns = tuple()
except ImportError: # die silently
patterns = tuple()
elif isinstance(module, (list, tuple)):
patterns = module
elif isinstance(module, types.ModuleType):
patterns = module.urlpatterns
else:
raise TypeError('Unsupported type: %s' % type(module))
for pattern in patterns:
urls.update(_get_urls_for_pattern(pattern, prefix=prefix, namespace=namespace))
return urls
It's probably not the best solution but so far it works.
And I don't know if it's important but the module that causes this error is the one detailled below (seems to be related to a string python module)
:
['add', 'class', 'contains', 'delattr', 'doc', 'eq', 'format', 'ge', 'getattribute', 'getitem', 'getnewargs', 'getslice', 'gt', 'hash', 'init', 'le', 'len', 'lt', 'mod', 'mul', 'ne', 'new', 'reduce', 'reduce_ex', 'repr', 'rmod', 'rmul', 'setattr', 'sizeof', 'str', 'subclasshook', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']