2010.1.3 备忘 django的get_absolute_url

django的get_absolute_url,还是挺有用的。 参考[这里](http://docs.djangoproject.com/en/dev/ref/models/instances/#get- absolute-url) from django.db import models @models.permalink def get_absolute_url(self): return ('people.views.details', [str(self.id)]) Or: (r'/archive/(?P<year>\d{4})/(?P<month>\d{1,2})/(?P<day>\d{1,2})/$', archive_view) @models.permalink def get_absolute_url(self): return ('archive_view', (), { 'year': self.created.year, 'month': self.created.month, 'day': self.created.day})

January 3, 2010 · notsobad

推荐韩娱《青春不败》

昨天晚上11点发现的这个娱乐节目。一连看了七集,到今天凌晨6点才睡的觉。 故事背景是:集合了几个当红美女组合中的若干成员,到首尔附近的一个村庄自力更生体验生活。让这些一直以来生活在聚光灯下的明星们体验一下农村的真实生活。 故事中。美女们需要团结协作,自力更生。通过帮助当地农民干活来换取一些生活必需品。自己做一些食物到市场去卖。其中不乏搞笑的片段。 故事中的主要明星有: 金泰宇(男) 金申英(女) Yuri(少女时代) sunny(少女时代) 荷啦(KARA ) 善花(Secret) 孝敏(T-ara) 玄雅(4minute) ...

January 3, 2010 · notsobad

How many things happened when I am sleeping?

又下雪了,今天12点多醒的时候,感觉窗户外边很亮,一看果然是下雪了。出去买东西的时候顺便拍了几张雪景的照片。 雪下的很大,已经可以埋住脚了,路上也堆满了积雪。 这三天每天都睡到12点以后,在我睡着的时候发生了多少事情啊!

January 3, 2010 · notsobad

Python不是java

Python不是java 同样,php也不是java, 用一种语言的思路来写另一种语言的代码,最后肯定是四不像。 有感。 原文: I was recently looking at the source of a wxPython-based GUI application, about 45.5KLOC in size, not counting the libraries used (e.g. Twisted). The code was written by Java developers who are relatively new to Python, and it suffers from some performance issues (like a 30-second startup time). In examining the code, I found that they had done lots of things that make sense in Java, but which suck terribly in Python. Not because “Python is slower than Java”, but because there are easier ways to accomplish the same goals in Python, that wouldn’t even be possible in Java. So, the sad thing is that these poor folks worked much, much harder than they needed to, in order to produce much more code than they needed to write, that then performs much more slowly than the equivalent idiomatic Python would. Some examples: * A static method in Java does not translate to a Python classmethod. Oh sure, it results in more or less the same effect, but the goal of a classmethod is actually to do something that’s usually not even possible in Java (like inheriting a non-default constructor). The idiomatic translation of a Java static method is usually a module-level function, not a classmethod or staticmethod. (And static final fields should translate to module-level constants.) This isn’t much of a performance issue, but a Python programmer who has to work with Java-idiom code like this will be rather irritated by typing Foo.Foo.someMethod when it should just be Foo.someFunction. But do note that calling a classmethod involves an additional memory allocation that calling a staticmethod or function does not. Oh, and all those Foo.Bar.Baz attribute chains don’t come for free, either. In Java, those dotted names are looked up by the compiler, so at runtime it really doesn’t matter how many of them you have. In Python, the lookups occur at runtime, so each dot counts. (Remember that in Python, “Flat is better than nested”, although it’s more related to “Readability counts” and “Simple is better than complex,” than to being about performance.) * Got a switch statement? The Python translation is a hash table, not a bunch of if-then statments. Got a bunch of if-then’s that wouldn’t be a switch statement in Java because strings are involved? It’s still a hash table. The CPython dictionary implementation uses one of the most highly-tuned hashtable implementations in the known universe. No code that you write yourself is going to work better, unless you’re the genetically-enhanced love child of Guido, Tim Peters, and Raymond Hettinger. ...

January 2, 2010 · notsobad

How about xml?

Some people, when confronted with a problem, think “I know, I’ll use XML.” Now they have two problems.

January 2, 2010 · notsobad

爱上生活爱上你

爱上生活爱上你 http://v.youku.com/v_show/id_XMTE3MTQ5NzMy.html 每天早上都被这个给吵醒。。。。。

January 1, 2010 · notsobad

2010.1.1

2010年1.1日 一年的第一天,不知道今年会怎么样 关于2009,Dot’t ask, Don’t tell.

January 1, 2010 · notsobad

django备忘

备忘: save() got an unexpected keyword argument ‘force_insert’ 解决: save时需要带上 *args, **kwargs def save(self, *args, **kwargs): #... super(SiteUser, self).save(*args, **kwargs) [参考](http://groups.google.com/group/django- users/browse_thread/thread/2471efd68d56ad59/a8c000a383db3f63?lnk=raot) 另: relation “django_admin_log” does not exist 这是因为启用了admin,但是没有syncdb 运行: ./manage.py syncdb

December 31, 2009 · notsobad

django 调试

django 调试 http://www.slideshare.net/simon/debugging-django 总结了几条: 1 使用断言 assert False assert False, variable 2 打印到终端 print “test” 3 使用logging模块 4 使用debugger 在view中: import pdb pdb.set_trace() 可以在运行时调试代码. python -i ./manage.py # import pdb;pdb.pm() 5 产品环境下, 将500,404之类的错误用email发给自己 6 使用xmpp,将产生的错误即时发给自己的msn,gtalk ...

December 30, 2009 · notsobad

vi的自动折行

vi的自动折行太贱了,写代码还好,我一个字符串很长,它也给我截断,字符串一截就给加了换行和tab 我忘了在哪里里配置的了,没办法,临时取消折行: set textwidth=99999

December 30, 2009 · notsobad