python - 尝试找出使用 Django 框架时出现的错误

标签 python django python-2.7

我是 Djnago 新手,打开 url - 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")

最佳答案

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

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

与:

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

关于python - 尝试找出使用 Django 框架时出现的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23198033/

相关文章:

python - 为什么文件处理程序不能在 python 中多次使用?

python - 如何在 Python 中重定向标准错误?

python - SpaCy:启用以前禁用的管道

Django admin : Filter by country. 仅显示非空国家/地区?

python - Django - ManyToMany 字段给用户返回 None

数据表过滤器或分页后 JavaScript 不工作

python - 如何读取python文本文件中的数字?

python - 如何在特定时间在 tmux 终端中运行 python 脚本?

python - 如何克服403 HTTP请求方法不允许的错误

python-2.7 - Pandas/matplotlib 条形图,颜色由列定义