Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - URL routing issues (cannot import name 'urls')

I am following the Django tutorial on https://docs.djangoproject.com/en/1.7/intro/tutorial03/, and am trying to get the index view to show up. I've tried the code specified on the page verbatim but keep on 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'm doing wrong. I keep getting an error that says "cannot import name 'urls'." any help would be appreciated!

like image 395
user3822741 Avatar asked Dec 01 '14 20:12

user3822741


1 Answers

The problem is in your import statement - there is no urls function in django.conf.urls package.

Replace:

from django.conf.urls import patterns, urls

with:

from django.conf.urls import patterns, url
like image 55
alecxe Avatar answered Oct 16 '22 04:10

alecxe