Differences between revisions 2 and 3
Revision 2 as of 2005-12-31 07:50:29
Size: 1963
Editor: ZoomQuiet
Comment:
Revision 3 as of 2009-12-25 07:10:31
Size: 1975
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 4: Line 4:
attachment:snap-tryDjango-2-0.png {{attachment:snap-tryDjango-2-0.png}}
Line 29: Line 29:
attachment:snap-tryDjango-2-debug.png {{attachment:snap-tryDjango-2-debug.png}}
Line 46: Line 46:
attachment:snap-tryDjango-2-1.png {{attachment:snap-tryDjango-2-1.png}}

LiClass2:加法器?

准备开始玩味 MTV (Model Template View) 按照说明一下子就成功了! snap-tryDjango-2-0.png 当然,没有使用 LiModou 说的那种 url 声明,追加的是: {{{(r'^add/$', 'tryfirst.apps.add.index'),

  • }}}

调试?!

POST 看起来是个内置对象,想法子输出看一下子!

   1 def index(request):    
   2     if request.POST.has_key('a'):
   3         a = int(request.POST['a'])
   4         b = int(request.POST['b'])
   5     else:
   6         a = 0
   7         b = 0
   8     return HttpResponse(text%(a
   9                             , b
  10                             , (a + b)
  11                             ,request.POST
  12                             )
  13                         )

当然的,在充当模板的text 部分要追加</form>debug::%s""" 

  • 唉呀呀??怎么没有输出!?
  • 对了是HTML 页面,可能有问题,看源代码!果然有了...

snap-tryDjango-2-debug.png

恶搞

哈哈哈!!这样调试可以的话,那未将输出部分修改一下子:

   1     return HttpResponse(text%(a
   2                             , b
   3                             , (a + b)
   4                             ,"dict4ini:%s : %s+%s=%s"%(str(r)
   5                                     ,str(r.a)
   6                                     ,str(r.b)
   7                                     ,str(int(r.a)+int(r.b))
   8                                     )
   9                             )
  10                         )

r 是什么呢?!r = DictIni(values=request.POST) 哈哈哈!使用 LiModou 的 dict4ini 模块!解析一下子dict 为对象,容易引用哪! 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 来访问得到?

DjangoLiClass2 (last edited 2009-12-25 07:10:31 by localhost)