随笔分类 - django
摘要:datetime to timespan:time.mktime(datetime.datetime.today().timetuple())string to timespan:since = '2010-1-1'time.mktime(time.strptime(since,"%Y-%m-%d"))
阅读全文
摘要:UnicodeDecodeError: 'utf8' codec can't decode byte 0xa1 in position 228: invalid start byte在django的html文件中用了…这个号会出错如上。…是半个中文省略号~
阅读全文
摘要:如果我想用本地图片帮定到django models的imagefield,要怎么做?如下:fromdjango.core.filesimportFileimg=File(open(your_local_image_file))s=some_model.create(image=img)s.save()即可~!
阅读全文
摘要:source:https://docs.djangoproject.com/en/dev/howto/custom-template-tags/如果想对一个值进行过滤,当然用的是filter但是会有这样的逻辑:当前页面有一个product对象和user对象,两个对象是多对多关系,所以会有一个关系表,我想以指定的逻辑去查询这个关系表的数据。做法:a 在views中实现指定的逻辑,直接render_to_response出来一些变量。b custom tag中实现指定的逻辑其中b在http://djangobook.py3k.cn/2.0/chapter09/中有说明。这里说一特别的地方:使用..
阅读全文
摘要:在render_to_response快捷方式中,有这样一个参数context_instance = RequestContext(request)这样是让当前页面有一个全局的变量共享(我一般视为auth的全局应用)这样就可以直接在页面用使用当前request中的一些全局变量。如 user.is_authenticated而当你这样用的时候:return render_to_response('template',{'user':'something'},context_instance = RequestContext(request))本地的
阅读全文
摘要:中文文件乱码?如果在windows下打开的话,可以试试用这个response.write('\xEF\xBB\xBF')这个是叫什么BOM的东西,应该是个历史问题,好了!这个要注意的是如果你要导入这个文件,就要先删除这个BOM啦!
阅读全文
摘要:#sudo apt-get install apache2 php5 libapache2-mod-php5#sudo apt-get install mysql-server mysql-client php5-mysql安装LAMP ............安装python-mysql#sudo apt-get install python-mysqldb安装djangohttps://www.djangoproject.com/download/以上网址有!/Files/snowleung/Django-1.3.1.rar方便大家,这里上传!安装方法tar xzvf Django-1.3
阅读全文
摘要:ImageFieldclassImageField(**kwargs)Default widget:ClearableFileInputEmpty value:Nonenormalizeto: AnUploadedFileobject that wraps the file content and file name into a single object.Validates that file data has been bound to the form, and that the file is of an image format understood by PIL.Error me
阅读全文