Django 之 "Hello Word"

简单页面

第一步:

  创建Django Pydev项目  ,使用CMD进入项目目录 Src(下面) ,输入命令 Python manage.py runserver  开启服务, 类似于用IIS部署aspx页面

第二部

  新建试图 views.py 文件

 

1 from django.http import  HttpResponse
2
3 def Index(request):
4 return HttpResponse("Hello Word")

第三部 配置配置路由

  在urls.py中

1 urlpatterns = patterns('',
2 (r'^Index/$',Index)
3 )

启动runserver默认使用8000端口,相应URL地址为 http://127.0.0.1:8000/Index/即可

接受url参数

   修改路由

urlpatterns = patterns('',
(r
'^Index/(\d+)/$',Index),
)

  试图Action中接受参数

  

def Index(request,id):
html
="<h1> Input id= %s </h1>" % int(id)
return HttpResponse(html)

貌似Python Django 速度灰常的快, 貌似超过了asp.net

另外由于本人刚接触,  ,比如此处我配置为Index,在地址中只能输入Http://xxx/Index,而 Http://xxx/index 就不行

希望高手指点下

原文地址:https://www.cnblogs.com/blackman/p/2143656.html