0%

Python Django 教程3

Python Django 教程3

本教程将聚焦于创建公共接口-视图。

Writing more views

更新views页面polls/views.py

1
2
3
4
5
6
7
8
9
def detail(request, question_id):
return HttpResponse("You're looking at question %s." % question_id)

def results(request, question_id):
response = "You're looking at the results of question %s."
return HttpResponse(response % question_id)

def vote(request, question_id):
return HttpResponse("You're voting on question %s." % question_id)

Write views that actually do something

A shortcut: render()

Raising a 404 error

A shortcut: get_object_or_404()

Use the template system

Removing hardcoded URLs in templates

Namespacing URL names

处无为之事,行不言之教;作而弗始,生而弗有,为而弗恃,功成不居!

欢迎关注我的其它发布渠道