Sharif
Sharif

Reputation: 703

ImportError: cannot import name 'include'

I am following django official tutorial-01. After editing the urls.py file I got this error:

ImportError: cannot import name 'include'

I have searched it here and got two solutions.

  1. To update the django version
  2. To include include in polls urls:
from django.conf.urls import include

I have tried these two solutions, but I'm still getting the error. Does anyone have any other solution?

Here is the screenshot of the terminal:

enter image description here

My django version is:

1.11.0

Edit: This is my urls.py:

from django.conf.urls import include
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    # url(r'^admin/', admin.site.urls),
    path('', views.index, name='index'),
    path('polls/', include('polls.urls'), name=none),
    path('admin/', admin.site.urls, name=none)
]

Upvotes: 9

Views: 17630

Answers (4)

Mohammed Nazary
Mohammed Nazary

Reputation: 11

I have faced to a similar problem lately that led me to your question.

If you are using django version 4.x like me, as it is mentioned here The url function was deprecated in v 3.1 and removed in v 4.0.

With removing line 16, line 18 could handle 'import inculde' easily.

Upvotes: 1

mm_
mm_

Reputation: 1735

I am using Django 3. Remember to activate the python environment where you run the python manage.py runserver . To do it you run /venv/bin$ source activate.

Upvotes: 2

polysgreg
polysgreg

Reputation: 1

Using Django 1.11.0 I had the following in my urls.py file:

from django.conf.urls import include

and in urlpatterns list:

url('',include(router.urls)),

Upvotes: 0

JPG
JPG

Reputation: 88579

I think you may be mixed up with the solutions.

If you are using Django==1.11.0 then import should be as

from django.conf.urls import include


else if you are using Django==2.x, the import should be as,

from django.urls import include

UPDATE
Your code seems written in Django 2.x. So you have to update the django version and remove the line 16 from the code

Upvotes: 13

Related Questions