Search code examples
pythondjangodjango-urlsdjango-rosetta

Cannot access rosetta


Versions:

  • Python 3.5.1
  • Django 1.10
  • django-rosetta 0.7.13

The installation guide tells you to add the following to your project's settings.py:

from django.conf import settings

if 'rosetta' in settings.INSTALLED_APPS:
    urlpatterns += patterns('',
        url(r'^rosetta/', include('rosetta.urls')),
    )

However, this just results in an error:

NameError: name 'patterns' is not defined

Solution

  • Searching for that problem reveals that one apparently has to import it:

    from django.conf.urls import patterns
    

    But still it doesn't work.

    ImportError: cannot import name 'patterns'
    

    This function was removed in django 1.10. However, one can add the rosetta urls conditionally using this approach:

    from django.conf import settings
    
    if 'rosetta' in settings.INSTALLED_APPS:
        urlpatterns.append(url(r'^rosetta/', include('rosetta.urls')))
    

    However, if you try to access rosetta at the url http://127.0.0.1:8000/rosetta/ you might be surprised to find that you still get a 404 Page not found.

    So it seems that the included patterns are not working properly. But they are. The problem is that there's a hidden requirement that one must be logged in when accessing the rosetta page (maybe with a staff/super user?). So, simply go to http://127.0.0.1:8000/admin/, log in, and then go to the rosetta url again. Now it should work.

    The installation does note this, sort of:

    Because Rosetta requires write access to some of the files in your Django project, access to the application is restricted to the administrator user only (as defined in your project’s Admin interface)

    How does it know you are an administrator if you are not logged in? It doesn't, and apparently instead of giving an informative error, it ignores the rosetta urls entirely.