Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Error on djangojs/init.js #51

Open
arno974 opened this issue Oct 17, 2014 · 0 comments
Open

Server Error on djangojs/init.js #51

arno974 opened this issue Oct 17, 2014 · 0 comments

Comments

@arno974
Copy link

arno974 commented Oct 17, 2014

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:

http://localhost:8000/djangojs/init.js

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']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant