主要参考
http://www.djangobook.com/en/2.0/chapter03.html
http://blog.csdn.net/thinkinside/article/details/7218340
http://djangobook.py3k.cn/chapter03/
遇到问题
1 是python版本:djanjo1.6.1 要在python2.6之上,而测试环境Linux系统的python版本是2.4.3 ,升级系统python
参考 http://www.cnblogs.com/lanxuezaipiao/archive/2012/10/21/2732864.html
2 一直报这个异常,找不到URL资源http://127.0.0.1:8000/time/
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order: ^hello/$ ^admin/ The current URL, time/, didn't match any of these.
下面说一下操作步骤:
1 执行命令 django-admin.py startproject mysite,生结果
2 在mysite目录下创建文件views.py
e:/django/mysite/mysite/views.py,内容是
from django.http import HttpResponse def hello(request): return HttpResponse("Hello world")
from django.conf.urls import patterns, include, url #from django.contrib import admin from mysite.views import hello // 添加行 #admin.autodiscover() urlpatterns = patterns('', # Examples: # url(r'^$', 'mysite.views.home', name='home'), # url(r'^blog/', include('blog.urls')), url(r'^hello/$', hello), // 添加的行 # url(r'^admin/', include(admin.site.urls)), )
python manage.py runserver
5 在浏览器地址栏输入 http://127.0.0.1:8000/hello/,看到结果Hello World
6 mysite下的目录结构