Django name patterns is not defined in ulrs.py

14,459

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'))]
Share:
14,459
0xtuytuy
Author by

0xtuytuy

Updated on June 04, 2022

Comments

  • 0xtuytuy
    0xtuytuy almost 2 years

    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'))
    )
    
  • 0xtuytuy
    0xtuytuy over 7 years
    Well the original error is gone but now i have: NameError: name 'include' is not defined
  • 0xtuytuy
    0xtuytuy over 7 years
    Here was the solution: from django.conf.urls import url, include