试图在Django框架上工作时弄清楚错误

时间:2014-04-21 13:04:08

标签: python django python-2.7

我是Djnago的新手,在打开网址时遇到以下错误 - 127.0.0.1/hello 可能有任何问题有助于解决这个问题..模块路径有一些错误,但如何解决它。

ImportError at /hello
No module named defaults
Request Method: GET
Request URL:    http://127.0.0.1:8000/hello
Django Version: 1.6.2
Exception Type: ImportError
Exception Value:    No module named defaults
Exception Location: /home/mkp/Desktop/djcode/mysite/mysite/urls.py in <module>, line 14
Python Executable:  /usr/bin/python
Python Version: 2.7.3
Python Path:    ['/home/mkp/Desktop/djcode/mysite',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-linux2',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PIL',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-client',
 '/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
 '/usr/lib/python2.7/dist-packages/ubuntuone-couch',
 '/usr/lib/python2.7/dist-packages/ubuntuone-installer',
 '/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol']
Server time:    Sun, 20 Apr 2014 16:42:25 +0000

urls.py: -

from django.conf.urls.defaults import patterns, include, url
from mysite.views import hello

urlpatterns = patterns('',
    url(r'^hello/$', hello),
)

views.py:-

from django.http import HttpResponse

def hello(request):
    return HttpResponse("Hello world")

1 个答案:

答案 0 :(得分:1)

您需要在urls.py中修复您的导入语句。替换:

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

使用:

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