== LiClass2:加法器? == '''准备开始玩味 MTV (Model Template View)''' 按照说明一下子就成功了! {{attachment:snap-tryDjango-2-0.png}} 当然,没有使用 LiModou 说的那种 url 声明,追加的是: {{{(r'^add/$', 'tryfirst.apps.add.index'), }}} === 调试?! === `POST` 看起来是个内置对象,想法子输出看一下子! {{{#!python def index(request): if request.POST.has_key('a'): a = int(request.POST['a']) b = int(request.POST['b']) else: a = 0 b = 0 return HttpResponse(text%(a , b , (a + b) ,request.POST ) ) }}} 当然的,在充当模板的text 部分要追加`debug::%s""" ` * 唉呀呀??怎么没有输出!? * 对了是HTML 页面,可能有问题,看源代码!果然有了... {{attachment:snap-tryDjango-2-debug.png}} === 恶搞 === 哈哈哈!!这样调试可以的话,那未将输出部分修改一下子: {{{#!python return HttpResponse(text%(a , b , (a + b) ,"dict4ini:%s : %s+%s=%s"%(str(r) ,str(r.a) ,str(r.b) ,str(int(r.a)+int(r.b)) ) ) ) }}}r 是什么呢?! '''r = DictIni(values=request.POST)''' 哈哈哈!使用 LiModou 的 dict4ini 模块!解析一下子dict 为对象,容易引用哪! {{attachment:snap-tryDjango-2-1.png}} 可用!是也乎`^__^` === URL 规则 === 没有详细说明下去的,url_conf,不知道是否有Apache mod_rewrite 的神奇? 比如说:`http://localhost:8000/foo?action=edit&user=zoomq` 可以通过:`http://localhost:8000/foo/zoomq/edit` 来访问得到?