Django - url routing issues (unable to import name 'urls')

I am following the Django tutorial at https://docs.djangoproject.com/en/1.7/intro/tutorial03/ and I am trying to show an index view. I tried the code given on the page but keep getting errors.

polls / urls.py:

from django.conf.urls import patterns, urls
    from polls import views

    urlpatterns = patterns('', 
    url(r'^$', views.index, name='index'),
)

      

mysite / urls.py:

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

urlpatterns = patterns('',
    url(r'^polls/', include('polls.urls')),
    url(r'^admin/', include(admin.site.urls)),

      

)

and finally the index method in views.py:

from django.shortcuts import render
from django.http import HttpResponse

# Create your views here.

def index(request): 
    return HttpResponse("<h1>Hello world!</h1>");

      

I'm not sure what I am doing wrong. I keep getting "Unable to import name" error. any help would be appreciated!

+3


source to share


1 answer


The problem is in your expression import

- there is django.conf.urls

no function urls

.

Replace:

from django.conf.urls import patterns, urls

      



from:

from django.conf.urls import patterns, url

      

+11


source







All Articles