Artem
Artem

Reputation: 1

Django first project import Error

My package: Python 2.7.11+ Django 1.9.6

In my urls.py I have imported:

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

but it's dysplays an error when I type python manage.py runserver:

ImportError: cannot import name patterns

I have tried to change import string with:

from django.conf.urls.defaults import

but it causes the following error:

from django.conf.urls.defaults import

Upvotes: 0

Views: 1290

Answers (2)

SHIVAM JINDAL
SHIVAM JINDAL

Reputation: 2974

patterns is deprecated after Django 1.7. You can defines urls simply like this

urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include('web.urls')),
]

or you can import urls from your app and define urls like this

from app import urls
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'', include(urls)),
]

Upvotes: 0

zooglash
zooglash

Reputation: 1775

Since Django 1.7, the urlconf is a simple list and no longer requires the patterns import. So remove patterns from your import, and see the example here on the syntax to use: https://docs.djangoproject.com/en/1.9/topics/http/urls/#example

Upvotes: 2

Related Questions