Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot import name patterns

Tags:

python

django

Before I wrote in urls.py, my code... everything worked perfectly. Now I have problems - can't go to my site. "cannot import name patterns"

My urls.py is:

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

They said what error is somewhere here.

like image 880
Autokilled Avatar asked Nov 10 '11 04:11

Autokilled


2 Answers

As of Django 1.10, the patterns module has been removed (it had been deprecated since 1.8).

Luckily, it should be a simple edit to remove the offending code, since the urlpatterns should now be stored in a plain-old list:

urlpatterns = [     url(r'^admin/', include(admin.site.urls)),     # ... your url patterns ] 
like image 93
Jacob Hume Avatar answered Sep 23 '22 04:09

Jacob Hume


You don't need those imports. The only thing you need in your urls.py (to start) is:

from django.conf.urls.defaults import *  # This two if you want to enable the Django Admin: (recommended) from django.contrib import admin admin.autodiscover()  urlpatterns = patterns('',     url(r'^admin/', include(admin.site.urls)),     # ... your url patterns ) 

NOTE: This solution was intended for Django <1.6. This was actually the code generated by Django itself. For newer version, see Jacob Hume's answer.

like image 36
juliomalegria Avatar answered Sep 21 '22 04:09

juliomalegria