[Fixed]-Django AttributeError 'tuple' object has no attribute 'regex'

51👍

You forgot the ‘url

url(r'^admin/', include(admin.site.urls)),
url(r'^tinymce/', include('tinymce.urls')),

urlpatterns should be a list of url() instances

url returns RegexURLPattern but instead a tuple is found in your list.

https://docs.djangoproject.com/en/1.8/_modules/django/conf/urls/#url

👤dting

4👍

I know it’s not absolutely related to the question, but sometimes this error can be a little deeper than directly in a urls.py file.

I got this error and the cause of the problem wasn’t in the error stack trace.

I had this problem while browsing the Admin with a custom Admin Class, and the problem was with the method get_urls() of this class, which was returning something like:

def get_urls(self):
    from django.conf.urls import patterns
    return ['',
            (r'^(\d+)/password/$',
             self.admin_site.admin_view(self.user_change_password))] + super(CompanyUserAdmin, self).get_urls()

To fix it:

def get_urls(self):
    from django.conf.urls import patterns
    return [
            url(r'^(\d+)/password/$',
             self.admin_site.admin_view(self.user_change_password))] + \
           super(CompanyUserAdmin, self).get_urls()

Don’t forget the import of ‘url’:

from django.conf.urls import url

Leave a comment