liuken@liuken-MS-7798:~$ python manage.py runserver
python: can't open file 'manage.py': [Errno 2] No such file or directory
liuken@liuken-MS-7798:~$ cd /usr/local/bin
liuken@liuken-MS-7798:/usr/local/bin$ python manage.py runserver
python: can't open file 'manage.py': [Errno 2] No such file or directory
liuken@liuken-MS-7798:/usr/local/bin$ ls
cftp django-admin.py manhole tap2deb tkconch
ckeygen lore pyhtmlizer tap2rpm trial
conch mailmail scrapy tapconvert twistd
liuken@liuken-MS-7798:/usr/local/bin$ cd ..
liuken@liuken-MS-7798:/usr/local$ cd ..
liuken@liuken-MS-7798:/usr$ cd ..
liuken@liuken-MS-7798:/$ cd home
liuken@liuken-MS-7798:/home$ cd liuken
liuken@liuken-MS-7798:~$ cd djcode
liuken@liuken-MS-7798:~/djcode$ cd mysite
liuken@liuken-MS-7798:~/djcode/mysite$ python manage.py runserver
Validating models...
0 errors found
July 31, 2013 - 07:04:05
Django version 1.5.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
/usr/local/lib/python2.7/dist-packages/django/conf/urls/defaults.py:3: DeprecationWarning: django.conf.urls.defaults is deprecated; use django.conf.urls instead
DeprecationWarning)
[31/Jul/2013 07:04:21] "GET / HTTP/1.1" 404 2002
[31/Jul/2013 07:04:59] "GET /hello HTTP/1.1" 301 0
[31/Jul/2013 07:04:59] "GET /hello/ HTTP/1.1" 200 11
http://127.0.0.1:800
开发服务器的地址是 http://127.0.0.1:8000/ ,打开你的浏览器访问 http://127.0.0.1:8000/hello/ 。 你就可以看到输出结果了。 开发服务器将自动检测Python代码的更改来做必要的重新加载
输出结果:
Hello world
向做到这些,你必须:
你需要输入到views.py文件:
from django.http import HttpResponse
def hello(request):
return HttpResponse("Hello world")
urls.py 文件
from django.conf.urls.defaults import *
from mysite.views import hello
urlpatterns = patterns('',
('^hello/$', hello),
)
我们做了两处修改。
简单来说,我们只是告诉 Django,所有指向 URL /hello/ 的请求都应由 hello 这个视图函数来处理。