我正在关注https://docs.djangoproject.com/en/1.7/intro/tutorial03/上的Django教程,并试图让索引视图显示出来。我已逐字尝试了页面上指定的代码,但继续收到错误。
轮询/ 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)),
)
最后是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>");
我不确定我做错了什么。我一直收到一条错误,上面写着“无法输入名称'网址'。”任何帮助,将不胜感激!
答案 0 :(得分:14)
问题出在您的import
声明中 - urls
包中没有django.conf.urls
功能。
替换:
from django.conf.urls import patterns, urls
使用:
from django.conf.urls import patterns, url