Cannot import name patterns

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

My urls.py :

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

They said what a mistake somewhere here.

+52
python django
Nov 10 '11 at 4:18
source share
7 answers

Import is not needed. The only thing you need in your urls.py (to run):

 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 is for Django <1.6. This was actually code created by Django himself. For a newer version, see Jacob Hume Response.

+17
Nov 10 2018-11-11T00:
source share

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

Fortunately, this should be a simple edit to remove the violation code, since urlpatterns should now be stored in a simple list :

 urlpatterns = [ url(r'^admin/', include(admin.site.urls)), # ... your url patterns ] 
+117
Aug 6 '16 at 1:25
source share

Yes:

 from django.conf.urls.defaults import ... # is for django 1.3 from django.conf.urls import ... # is for django 1.4 

I also met this problem.

+17
Oct 22 '12 at 10:41
source share

template module is not supported .. mine worked with this.

 from django.conf.urls import * from django.contrib import admin admin.autodiscover() urlpatterns = [ url(r'^admin/', include(admin.site.urls)), # ... your url patterns ] 
+9
Aug 24 '16 at 4:35
source share

This is the code that worked for me. My django version 1.10.4 final

 from django.conf.urls import url, include from django.contrib import admin admin.autodiscover() urlpatterns = [ # Examples: # url(r'^$', 'blog.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^admin/', include(admin.site.urls)), ] 
+4
Dec 26 '16 at 2:57
source share

Template module is not available from django 1.8. Therefore, you need to remove the template from your import and do something similar to the following:

 from django.conf.urls import include, url from django.contrib import admin admin.autodiscover() urlpatterns = [ # here we are not using pattern module like in previous django versions url(r'^admin/', include(admin.site.urls)), ] 
+2
May 16 '17 at 12:46
source share

I decided to clone my project directly into Eclipse from GIT,

First, I cloned it at a specific location in the file system, and then imported it as an existing project in Eclipse.

0
Jan 02 '14 at 8:03
source share



All Articles