摘要: 自定义字段标签自定义一个标签, 你只需在模块中指定verbose_name=' 'from django.db import models# Create your models here.from django.db import modelsclass Publisher(models.Mode... 阅读全文
posted @ 2015-04-04 19:08 牧歌- 阅读(146) 评论(0) 推荐(0) 编辑
摘要: 为了方便, 使用chinaunix的账户获取账户主题. 有些网站可能需要验证码, 找一些不用验证码的网站下面 ****** 很多个星号的均为私密信息, 所以用星号代替#!/usr/bin/python# -*- encoding:utf-8 -*-import urllibimport urllib... 阅读全文
posted @ 2015-04-04 14:49 牧歌- 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 判断字符串编码使用 chardet 可以很方便的实现字符串/文件的编码检测。尤其是中文网页,有的页面使用GBK/GB2312,有的使用UTF8,如果你需要去爬一些页面,知道网页编码很重要>>> import urllib>>> html = urllib.urlopen('http://www.ch... 阅读全文
posted @ 2015-04-04 13:50 牧歌- 阅读(19099) 评论(1) 推荐(2) 编辑
摘要: 如果使用这种方法制作文章肯定不是一个好方法,尽管它便于你理解是怎么工作的。def current_datetime(request): now = datetime.datetime.now() html = "It is now %s." % now return HttpRes... 阅读全文
posted @ 2015-04-02 15:18 牧歌- 阅读(146) 评论(0) 推荐(0) 编辑
摘要: The Django Book学习笔记 04 模板The Django Book学习笔记 06 admin 阅读全文
posted @ 2015-04-02 15:05 牧歌- 阅读(134) 评论(0) 推荐(0) 编辑
摘要: >>> import datetime>>> now = datetime.datetime.now()>>> nowdatetime.datetime(2015, 4, 2, 12, 18, 37, 962347)>>> print now2015-04-02 12:18:37.962347dat... 阅读全文
posted @ 2015-04-02 12:18 牧歌- 阅读(236) 评论(0) 推荐(0) 编辑
摘要: %s 用str()方法处理对象%r 用rper()方法处理对象,打印时能够重现它所代表的对象(rper()unambiguously recreate the object it represents)例一:>>> print("Today is %s" % a)Today is sunday>>>... 阅读全文
posted @ 2015-04-01 18:56 牧歌- 阅读(389) 评论(0) 推荐(0) 编辑
摘要: 让Python的经验更多一点Python while 1 和 while True 速度比较Python %s和%r的区别 阅读全文
posted @ 2015-04-01 13:16 牧歌- 阅读(140) 评论(0) 推荐(0) 编辑
摘要: Referenceshttp://legacy.python.org/dev/peps/pep-0285/http://stackoverflow.com/questions/3815359/while-1-vs-for-whiletrue-why-is-there-a-difference本文内容... 阅读全文
posted @ 2015-04-01 13:14 牧歌- 阅读(5772) 评论(0) 推荐(1) 编辑
摘要: 正则表达式 regular expression 用来匹配一系列符合句法规则的字符串,是一门独立的小型的语言,如果你了解类Unix系统,那么你对正则表达式就一定不陌生。正则表达式的概念最初是由Unix中的工具普及开的(如: sed grep)。Python中也内嵌了正则表达式,通过re模块实现。正... 阅读全文
posted @ 2015-03-30 16:57 牧歌- 阅读(319) 评论(0) 推荐(0) 编辑