Rémi Rémi - 10 days ago 6
Python Question

Django name patterns is not defined in ulrs.py

I am trying to set up a Django app, but everytime I try to run it i get the following error message: NameError: name 'patterns' is not defined

I do not understand what is wrong with my urls.py file, here is a copy of it:

from django.contrib import admin
from rest_framework import routers
from SecMeRe import views

router = routers.DefaultRouter()
#makes sure that the API endpoints work
router.register(r'api/SecMeRe', views.PatientViewSet)
admin.autodiscover()

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

Answer

Use this:

from django.conf.urls import url, include
urlpatterns = [
  url(r'^admin/', include(admin.site.urls)),
  url(r'^', include(router.urls)),
  url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))]