'Stuck in urls.py while migrating a website from Python 2 to Python 3

 urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html'])

While running manage.py makemigrations, got this error and was stuck in this error for a day .

This is the error I received

File "C:\Users\DSS-WT\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\urlpatterns.py", line 112, in format_suffix_patterns return apply_suffix_patterns(urlpatterns, suffix_pattern, suffix_required, suffix_route)

File "C:\Users\DSS-WT\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\urlpatterns.py", line 59, in apply_suffix_patterns regex = urlpattern.pattern.regex.pattern.rstrip('$').rstrip('/') + suffix_pattern

AttributeError: 'tuple' object has no attribute 'pattern'

This is my urls.py (Note: it is shorted because of more than 400 lines)

App/urls.py

urlpatterns =  [
    re_path(r'^$', views.index, name='index'),

    #==== Role ===

    re_path(r'^getorinsertroleAPI/$', views.getorinsertroleAPI, name='getorinsertroleAPI'),
    re_path(r'^updateordeleteroleAPI/(?P<pk>[0-9]+)/$', views.updateordeleteroleAPI, name='updateordeleteroleAPI'),

    #==== Register ===

    re_path(r'^registerUser/$', views.registerUser, name='registerUser'),
    re_path(r'^registerFBUser/$', views.registerFBUser, name='registerFBUser'),
    re_path(r'^admin/registerCoach/$', views.registerCoach, name='registerCoach'),

    #==== Login ===

    re_path(r'^login/$', views.loginMethod, name='loginMethod'),
    re_path(r'^getUserId/$', views.getUserId, name='getUserId'), 

]

urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html'])

views.py

@csrf_exempt
def  getHealthyLivingListByUser(request, format=None):
    if request.method == 'POST':
        try:
            request_params=json.loads(request.body)
            limit=request_params.get('limit')
            offset=request_params.get('offset')
            limit=offset+limit
            tasks = tbl_healthyliving.objects.filter(status=1).order_by('-syndicateid')
            totalrecords=len(tasks)
            tasks=tasks[offset:limit]
            serializer = tbl_healthylivingSerializer(tasks, many=True)
            return JsonResponse({'Response':'Success','Response_status':1,'totalrecords':totalrecords,'healthyliving':serializer.data}) 
        except Exception as e:
            return HttpResponse(status=500,content_type="application/json",content=json.dumps({'Response':'Failure','Response_status':'Invalid data provided','Error':e.message}))
    else:
        return HttpResponse(status=405,content_type="application/json",content=json.dumps({'Response':'Failure','Response_status':'Method not allowed'}))

Project/urls.py


urlpatterns = path(' ', (include('Health.urls')),
# (r'^o/', include('oauth2_provider.urls', namespace='oauth2_provider')),
# (r'^admin/', include(admin.site.urls)),
# (r'^authorize/', include('rest_framework.urls', namespace='rest_framework')),
                ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)




Solution 1:[1]

I believe urlpatterns should be a list, I believe your urls.py is currently incorrect.

urlpatterns = [
  path(' ', include('Health.urls'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mikicz