我使用Ubuntu 10,蟒蛇2.6.5这是Django教程或包问题的问题,还是我?
我下面这个教程:http://www.djangobook.com/en/2.0/chapter02
我使用剪切和粘贴遵循所有的步骤。 以下的目录结构被自动创建:
[email protected]:~/projects$ ls -l mysite
total 36
-rw-r--r-- 1 bill bill 0 2010-09-01 08:18 __init__.py
-rw-r--r-- 1 bill bill 546 2010-09-01 08:18 manage.py
-rw-r--r-- 1 bill bill 20451 2010-09-01 18:50 mysite.wpr
-rw-r--r-- 1 bill bill 3291 2010-09-01 08:18 settings.py
-rw-r--r-- 1 bill bill 127 2010-09-01 11:13 urls.py
-rw-r--r-- 1 bill bill 97 2010-09-01 08:20 views.py
urls.py
from django.conf.urls.defaults import *
import sys
print sys.path
from mysite.views import hello
urlpatterns = patterns('',
(r'^hello/$', hello),
)
pylint的产生这样的错误:无法导入 'mysite.views'
views.pyfrom django.http import HttpResponse
def hello(request):
return HttpResponse("Hello world")
[email protected]:~/projects/mysite$ python manage.py runserver
Validating models...
0 errors found
Django version 1.2.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
其中导致:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
1. ^hello/$
The current URL, , didn't match any of these.
为什么在主目录中的view.py包含以下内容?
from mysite.views import hello
没有子目录'views'。虽然我熟悉使用包,但我从来没有创建自己的需求,所以我有点困惑。我会认为from views import hello
是正确的。
一步一步的教程看起来很简单,我还没有看到任何人遇到这个问题,所以我有点困惑,我做错了什么。
可能完全不正确,但应该'r'^ hello/$''是'r'^/hello/$''? – dbr 2010-09-03 13:41:04
@dbr:不,语法是正确的。 – 2010-09-03 13:42:50
本教程告诉你去'http://127.0.0.1:8000/hello/' – 2010-09-03 13:55:25