0
from django.conf.urls import patterns, include, url

urlpatterns = patterns('',
    url(r"^$", home),
    url(r"^storefront/", storefront),
    url(r"^sell/", get_entry),

.

ImportError: cannot import name patterns

The above is a snippet of my urls.py, is fixing this just a matter of changing my import statement or will I literally need to rewrite my entire urls.py now that the patterns module has been deprecated?

david
  • 6,303
  • 16
  • 54
  • 91
  • 4
    Did you read the [release notes](https://docs.djangoproject.com/en/1.10/releases/1.8/#django-conf-urls-patterns)? – knbk Nov 10 '16 at 20:08
  • ah thanks. did not see this. that answers my question. – david Nov 10 '16 at 20:12
  • 1
    Possible duplicate of [New url format in Django 1.9](http://stackoverflow.com/questions/34108321/new-url-format-in-django-1-9) – Selcuk Nov 11 '16 at 02:53

1 Answers1

2

In django 1.10 the urls can be defined in the following way:-

from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns

urlpatterns = i18n_patterns(
    url("^admin/", include(admin.site.urls)),
)

if settings.USE_MODELTRANSLATION:
    urlpatterns += [
        url('^i18n/$', set_language, name='set_language'),
    ]

urlpatterns += [
    url("^", include("your_app.urls")),
]

So you dont have to change all your urls. Just place correctly i.e if you are useing I18N place them with admin in urlpatterns = i18n_patterns section else in another section as in example above replace the name with your_app.urls.

Shashishekhar Hasabnis
  • 1,636
  • 1
  • 15
  • 36