Django-rest-framework: ImproperlyConfigured regular expression on DefaultRouter (format suffixes)

Created on 7 Jan 2014  路  12Comments  路  Source: encode/django-rest-framework

While running the tutorial (part 6), I got an error after implementing DefaultRouter on my urls.py:

ImproperlyConfigured: "^users/(?P<pk>[^/]+)/\.(?P<format>[a-z0-9]+)\.(?P<format>[a-z0-9]+)$" is not a valid regular expression: redefinition of group name 'format' as group 3; was group 2

The format suffixes are duplicated in regex. My urls.py is pretty basic:

router = DefaultRouter()
router.register(r'tasks', views.TaskViewSet)
router.register(r'users', views.UserViewSet)

urlpatterns = patterns('',
    url(r'^', include(router.urls)),
    url(r'^auth/', include('rest_framework.urls', namespace='rest_framework')),
)

On DefaultRouter, setting include_format_suffixes to False solved the problem. Is there a bug or I'm doing something wrong?

Python 3.3
Django 1.6.1
Django REST Framework 2.3.10

Most helpful comment

Just found out what's happening. I didn't removed the last line on urls.py when refactoring:

urlpatterns = format_suffix_patterns(urlpatterns)

All 12 comments

Just found out what's happening. I didn't removed the last line on urls.py when refactoring:

urlpatterns = format_suffix_patterns(urlpatterns)

Faced same issue! format_suffix_pattern was the problem! lol!

Thank you !! @jrvidotti

I met the same question,thank you

You are my savior, thanks

damn, you're a legend, even stackoverflow didn't have the solution!

Or you can write format_suffix_pattern before adding (appending) router.urls to urlpatterns

Really thank you!!

2020, happened to me too lol

Same here, you save my time !

same here , if DEBUG = True

Just commented to remind you that you are a hero @jrvidotti!

Was this page helpful?
0 / 5 - 0 ratings