Django community: Django links RSS
This page, updated regularly, aggregates Django links from the Django community.
-
Por dentro dos signals do Django // Python, Django, NoSQL, HTML5, Arduino, jQuery, Web 2.0, etc et al // Marinho Brandão
-
Making a Facebook app (with Django) – part 3: Python & FBML - Chicken Wing Software
-
Django localflavor for models? Default widget? - Stack Overflow
-
macagua/django-local-flavor-ve - GitHub
-
Django tips: extending the User model
-
authentication - Extending the User model with custom fields in Django - Stack Overflow
-
Specifying a mySQL ENUM in a Django model - Stack Overflow
-
8 web design add-ons for Django
-
在Heroku建立一个App遇到问题解决办法
heroku建立app的时候,首先需要git和ssh,sudo apt-get install git-core sudo apt-get install ssh 执行了两条ubuntu命令后,算是顺利完成安装了。gem install heroku 安装heroku之后,要建立一个app;heroku create,帐号认证,竟然出现错误:No ssh public key found in /home/***(计算机名)/.ssh/id_[rd]sa.pub. You may want to specify the full path to the keyfile.帐号没有错,刚刚在heroku上激活的,而且我也已经生成了ssh key ,输入ssh-keygen -t rsa 后,认认真真输入key和pass..最后出来的数字码和随机图,都没有什么异常。但到了建立app的时候,死活进不去,出来总是:No ssh public key found in /home/***(计算机名)/.ssh/id_[rd]sa.pub. You may want to specify the full path to the keyfile.正在纳闷的时候,重新生成ssh key;不经意没有输入key和pass,ssh-keygen -t rsa 一路回车,同样也生成了shh 数字码和随机图,建立app的时候意外的成功了!玄乎.... -
比较Perl、PHP、Python、Java和Ruby
!预览语言的发展趋势一定是动静结合、刚柔并济Perl凝练晦涩,Python优雅明晰,Ruby精巧灵动,PHP简明单纯或许优雅正是来自对细节和规范的重视(RoR)与Ruby结合之后,便如一只猱身而上灵猫,立刻衬托出Java和.NET大象般的身影?提问Perl、Python、Ruby和PHP各自有何特点?为什么动态语言多作为轻量级的解决方案?LAMP为什么受欢迎?Ruby on Rails为什么会流行?编程语言的发展趋势是什么?:讲解“剩下四种动态语言,我们将之归为后台脚本语言。”冒号说着画了张图表——引号听得仔细:“我记得您开始是把这些语言划分为C族静态语言、非C族静态语言和动态语言三类的。”冒号解释:“那是按语法来划分的,偏重理论;现在是按应用来划分,偏重实践。”句号旋即联想到:“这种分法貌似三层架构——前台语言对应表现层;平台语言和后台脚本语言对应业务逻辑层;系统语言对应数据层。”“的确有几分神似,但千万不可混淆。”冒号提醒道,“三层架构(three-layer architecture)是模块设计上的逻辑划分[1];而这里是按语言应用范围进行的物理划分——与用户交互的是前台语言,与机器交互的是系统语言,介于其中的为前台提供服务同时又需要底层系统服务的是后台语言。”逗号询问:“后台语言又细分成平台语言与后台脚本语言?”“这是基于程序(program)与脚本(script)、静态与动态而分的。”冒号进行说明,“其实Perl,PHP,Python和Ruby都有自己的虚拟机(virtual machine),从这种意义上说它们也可作为平台语言。但在实际应用中,它们没有Java平台和.NET平台那种整合凝聚力和核心作用,通常作为轻量级的解决方案。”问号想探个究竟:“这是由于它们都是动态语言的缘故吗?”冒号回答:“理论上动态语言同样能承担大型应用,但实践上它们多作为粘合语言或用于中小型应用。用句时髦的话来形容,暂时还是主流的配角或非主流的主角。毕竟在运行效率、类型安全、可用资源、开发工具、技术支持等方面,它们与Java、C#相比尚有一定差距。另外它们同属‘草根’语言,虽有开源社区的大力支持,在影响力上与后者未可同日而语。”叹号揣测:“说不定在不久的将来,动态语言也会成为主流的主角。”“世易时移,殊难逆料。但有一点可以肯定,语言的发展趋势一定是动静结合、刚柔并济。”冒号断言,“一方面以Java和C#为代表的静态语言中嫁接了动态语言的枝条;另一方面以Java和.NET为代表的平台与动态语言的交壤地带也在逐步扩大。比如JRuby允许Ruby与Java之间互相调用,类似的还有Jython、IronRuby、IronPython等等。此外值得一提的是,动态语言最活跃的舞台当数LAMP,L-A-M-P。”引号接茬:“L是Linux,A是Apache,M是MySQL,P是PHP。这四大组件形成了一个完整的开源网络开发平台。”冒号补充道:“P也可指Perl、Python,甚至Ruby。”逗号调侃:“可惜Ruby的‘R’比‘P’多了一根尾巴。”“有人为了自圆其说,干脆让P表示‘Programming language’,这下所有语言都囊括其中了。老外就喜欢玩这种首字母缩略(acronym)的文字游戏,尤其LAMP正好还有‘灯’的含义,寓意开源世界的一盏明灯,他们一定更得意了。”冒号语带调笑,“前面我们曾提及,网络应用是生长动态语言最肥沃的土壤,而LAMP就是这块土壤上搭建的平台。作为网络平台,LAMP以其开放灵活、开发迅速、部署方便、高可配置、安全可靠、成本低廉等特色而与Java平台和.NET平台鼎足三分,尤其受中小企业的欢迎。LAMP中Linux是操作系统,Apache是Web服务器,MySQL是数据库系统,而我们当下最关心的是‘P族语言’:PHP、Perl、Python还有Ruby。”问号建议:“作为动态语言,它们的共性上节课已经谈了不少,能说说它们的个性吗?”“它们的个性极为鲜明:Perl凝练晦涩,Python优雅明晰,Ruby精巧灵动,PHP简明单纯。先看老大哥Perl,它博采众家之长,综合了C语言的结构、sed的正则表达式、AWK的关联数组(associative array)、Lisp的表(list)和Unix Shell的命令,此外还有借鉴了一种语言,你们知道是哪种吗?”冒号忽然卖了个关子。逗号猜想:“应该是某种OOP语言吧。”“Perl中确有不少C++的影子,但它的对象模型在5.0以后才引入,典型的半路出家,远不如前面的特征那么自然。与其说是一种自然而然的发展,不如说是在OOP潮流裹挟下的一种身不由己的迎合。真正深入骨髓的借鉴是自然语言。”冒号给出了答案,“我们提过,Perl的发明者Larry Wall是一名语言学家,他认为程序语言应该与自然语言一样,简洁自然、易读易写、表达多样、不拘一格。Perl还有不少的格言或哲学,使得编程语言一改严谨刻板的面孔,散发出浓郁的人文气息。”叹号幽了一默:“我见过Perl的代码,人文气息没闻出来,但我怀疑有乙醚气息——看一会就觉得晕晕乎乎的。”众人大笑。“有人仅用一行Perl代码就实现了RSA算法,你看了那还不得当场晕倒啊?”冒号打趣道,“Perl的各种魔符好似一把把锋利的剪刀,做起文本裁剪之类的工作来游刃有余。这是它最大的长处,当初Perl就是Wall用来做Unix系统管理的,以后在CGI上的广泛应用也得益于此。这也赋予Perl极强的粘合力,因而有‘internet上的胶带(duct tape)[2]’的说法。它又号称瑞士军刀,精练而复杂,实用而强大。但Perl过于灵活自由,缺乏规范,影响了程序的可读性、一致性、整洁性和可维护性。不熟悉该语言的固然如读天书,熟悉语言而不熟悉问题的也颇费思量。相比之下Python被认为是Perl有力的挑战者,不仅在于它天然的OO设计和丰富的类库,更重要的是它对程序员友好度大大超过Perl。Python也有一系列的被称为禅(Zen)的哲学,不少与Perl是针锋相对的。比如:Perl认为做一件事可以有多种方法,而Python认为一件事应该最好只有一种方法;Perl追求语言的表现力,Python追求简单优雅;Perl喜欢隐性暗示,Python强调显性明示;Perl强调紧凑,Python强调松散; Perl的语法和语义丰富,Python的语法和语义简单而类库丰富。或许Python最让人不习惯的是它对空白符敏感性。”引号感到惊奇:“对空白符敏感?这个倒真怪异。”冒号见惯不怪:“虽然有点违反习惯,但非常符合Python一贯的规范简洁的风格——一方面从语法上保证了良好的编码风格;另一方面,每个代码块不再需要起始的大括号或begin/end之类的,减少了的代码行数。顺便插一句,另外一种优雅的语言Haskell同样对空白符敏感,或许优雅正是来自对细节和规范的重视吧。此外许多人抱怨Python中的自引用self太多,殊不知这也是它倡导显式表达的一种体现。总的看来,Python主要的问题还是在性能效率上不尽如人意。”叹号好奇地问:“Ruby怎么样?据说它将取代Java。”“不要轻言‘取代’二字。”冒号规诫道,“Java没有取代C++,也不会被Ruby取代,至多只是一种再分配。不过Ruby的确是门很可爱的语言,兼具Perl的表现力和Python的可读性。Ruby背后最具特色的理念是:关注程序员使用语言时的感受超过语言本身的功能。通俗地说,兵器的称手比锋利更重要;文雅地说,应给予程序员更多的人文关怀。就拿代码块(block)和迭代器(iterator)来说,虽然均非Ruby首创,但其语法最为赏心悦目。类似的例子比比皆是。Ruby的元编程能力特别强,也是它高度灵活的一种体现,但并不是所有人都喜欢这种风格。Ruby的主要弱点有两个:一个与Python类似,在性能上还有待提高;另一个是它的线程由用户空间(user space)而不是内核空间(kernel space)来管理[3],不能充分利用多核或多CPU。真正让Ruby变得炙手可热的是web应用框架 Ruby on Rails(RoR)的成功,它们还催生了Java平台上的Groovy语言和Groovy on Grails框架。RoR奉行的CoC(Convention over Configuration)和DRY(Don't repeat yourself )原则以及MVC架构看似了无新意,但与Ruby结合之后,便如一只猱身而上灵猫,立刻衬托出Java和.NET大象般的身影。”逗号有些怀疑:“框架竟然捧红了语言,框架真有这么重要吗?”“如果web应用中动态页面较少或业务逻辑不复杂,框架的价值并不大。以前CGI编程就是往Perl之类的代码中嵌入HTML代码,如同Java中的Servlet;PHP则单纯地在HTML代码中插入PHP代码,如同早期的JSP。没有MVC,也不管什么三层架构,更没有ORM。但是——”冒号拖了个转折音,“一旦业务逻辑变得复杂,开发人员增多,手工作坊式编程开始捉襟见肘,引入框架这个流水生产线来提高生产力便是大势所趋。”句号不解:“我想Perl、Python和PHP一定也有不少框架,Java中的框架更是泛滥成灾,何以独独RoR脱颖而出?”冒号作出分析:“正值web2.0和敏捷开发(agile development)的概念流行之际,RoR将AJAX与Ruby组合在一起成为绝佳的回应。以前各种web应用框架是不少,但在RoR之前轻量级套餐式解决方案并不多。Perl中的Catalyst、Python中的Pylon还有PHP中的CakePHP等应是效仿之作。因此RoR出现的时机可说是不早不晚,正当其时。此外,Perl和PHP由于过于流行,反而有不少的历史包袱,人们习惯了将表示逻辑和业务逻辑编织在一起。至于Java企业解决方案,框架太多,搭配组合更多,增加了选择的难度。即使采用最常见的轻量级SSH(Struts+Spring+Hibernate)组合,维护起来也比RoR繁杂得多。”叹号愈发担忧:“听这意思,Java还是危险啊!”“言之过早。”冒号不以为然,“首先RoR还有待进一步检验,目前无论是应用广度还是深度上尚无法与Java相提并论;其次Java在性能、安全等方面还是有不少优势,而这些对于大型和关键性的应用来说尤为重要。即使在中小型web应用中,RoR较之PHP还远为不及。”问号接下话题:“PHP为何如此流行?”“因为它简单、专一。”冒号答得很干脆,“与Python和Ruby一开始就定位通用语言不同,PHP是专为网络而生的。同早期的Perl相似,PHP起初主要起文本过滤器的作用,只不过Perl多处理文件流(file stream),而PHP多处理套接字流(socket stream)。PHP的语法简单,且为网络应用度身定造,受到网络开发人员的追捧当在情理之中。它虽很实用很流行,但并不完美。比如:变量名大小写敏感而函数名大小写不敏感;函数命名规则不一致;不支持namespace和unicode[4];与Perl一样,它的对象模型不是先天的,直到PHP 5才真正完善;对线程支持不足;相比Perl、Python和Ruby,它的功能稍显单薄等等。”引号突然想起:“我记得您在第一堂课提到PHP还能用于桌面应用。”“不仅PHP,Perl、Python还有Ruby,都能作为前台语言来开发命令行或图形界面的应用。同样地,VB、Delphi和JavaScript也能作为后台语言。现代的程序语言既有自己的专长,又向通用化和全能化发展,以争取更多的生存空间。试想一下,现代的程序员又何尝不是如此呢?”言及于此,冒号收住话题,“语言简评告一段落,还有不少既有趣又有用的语言,在此就不一一评说了。我们看到,每种编程语言都有其独特的惯例用法和哲学理念,它们与编程范式一道形成了语言的编程风格。体悟愈深者编程语感愈强,思维与语言愈交融无碍,渐从必然王国走向自由王国。”逗号满怀憧憬:“那是不是一种人剑合一的境界?”“或许人器合一更准确吧,程序员可不能只会一种兵器哟。”冒号故意抠他的字眼,“现在请大家每人写一句对本节课的感言。”众人沉思片刻,齐齐挥笔而就——叹号——没有最好的语言,只有最合适的语言。逗号——没有糟糕的语言,只有糟糕的程序员。问号——没有一种语言是万能的,只会一种语言是万万不能的。引号——废除对语言的宗教信仰,建立对语言的哲学思维。句号——编程就是在人脑和电脑之间寻找最佳平衡点的过程。冒号读罢大悦,顺手一掌拍出五记马屁:“精彩之极!可谓字字珠玑、句句联璧啊。兹决定,给诸位的奖赏是——立时下课!”众人欣然领赏而去。插语[1] 有两种三层架构,一种是three-layer architecture,一种是three-tier architecture。它们经常换用,但其实是有分别的:前者仅仅在逻辑进行划分,而后者在物理上也进行了划分——不同层次的模块运行在不同的主机上。[2] 不少地方译作‘输送带’、‘传送带’,因为duct有‘输送管’、‘导管’之意,于是想当然地认为这表明Perl在internet上起着输送作用。殊不知‘duct type’专指一种万能的粘性极强的胶带,用以比喻Perl的粘合力。[3] 这类线程被称为绿色线程(green thread),也称伪线程。据称Ruby2.0将支持原生线程(native thread)。[4] PHP将在5.3.0支持namespace,将在6.0支持unicode。总结比起Java平台和.NET平台,动态语言轻便灵活、开发效率高,但整合凝聚力还不够,在运行效率、类型安全、可用资源、开发工具、技术支持以及影响力等方面也有一定差距,故通常作为轻量级的解决方案。LAMP是由Linux、Apache、MySQL和包括PHP、Perl、Python或Ruby在内的脚本语言组成的网络开发平台,具有开放灵活、开发迅速、部署方便、高可配置、安全可靠、成本低廉等优点。Perl精练、复杂、强大、灵活、自由、隐晦、表现力强,但规范性、可读性、一致性、整洁性和可维护性较差。Python优雅规范、简洁明晰、易学易用、类库丰富,但效率稍差,有些人不喜欢它对空白符敏感的特性。Ruby语法精巧、高度灵活,兼具Perl的表现力和Python的可读性,尤其注重程序员的感受,但其性能和线程模型尚有待改进。PHP简单、专一、实用、流行,在但相比其他三种语言,在语法和功能上稍有欠缺。RoR是一种轻量级套餐式的web应用解决方案,是友好的设计(MVC架构和CoC、DRY原则)加上好的语言(Ruby)在好的时机(web2.0和敏捷开发风行之际)打造出的好的框架。静态语言与动态语言从语言特征到运行环境都在逐渐融合。程序员应该与程序语言一样,既要有自己的专长,又要向通用化和全能化发展。编程语言惯例用法、哲学理念和编程范式形成了语言的编程风格。 -
Ubuntu下安装MySQL
Linux新手,常常为现在源码 编译 安装感到迷茫,今天在Ubuntu官方上找到简易安装MySQL的方法,以便以后配置开发环境做备忘录.以下是通过Ubuntu的终端通过远程源来安装MySQL。之前最好更改系统的源为中国源,1 更改到中国源系统的顶端菜单 系统--更新管理器--(底下左边)设置(输入管理员root密码)--Ubuntu软件--下载自 <选择> 其他站点--中国的 mirrors.163.com(根据你使用的带宽来选择吧)2 安装MySQL要安装 MySQL,可以在终端提示符后运行下列命令:sudo apt-get install mysql-server mysql-client #中途会让你输入一次root用户密码sudo apt-get install php5-mysql #安装php5-mysql 是将php和mysql连接起来一旦安装完成,MySQL 服务器应该自动启动。sudo start mysql #手动的话这样启动sudo stop mysql #手动停止当你修改了配置文件後,你需要重启 mysqld 才能使这些修改生效。要想检查 mysqld 进程是否已经开启,可以使用下面的命令:pgrep mysqld如果进程开启,这个命令将会返回该进程的 id。3 文件结构MySQL配置文件:/etc/mysql/my.cnf ,其中指定了数据文件存放路径datadir = /var/lib/mysql如果你创建了一个名为 test 的数据库,那么这个数据库的数据会存放到 /var/lib/mysql/test 目录下。4 进入MySQLmysql -uroot -p (输入mysql的root密码)baoyalv@ubuntu:~$ mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 37Server version: 5.1.41-3ubuntu12.3 (Ubuntu)Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 修改 MySQL 的管理员密码:sudo mysqladmin -u root password newpassword5 简单的操作显示数据库:mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql |+--------------------+2 rows in set (0.00 sec)6 phpmyadmin管理用随便一个支持PHP的web服务器(如Apache、Nginx、Lighttpd),下载phpmyadmin,装之。sudo apt-get install phpmyadmin #注意这是安装到/usr/share/phpmyadmin -
Windows上安装Nginx注意事项
本来想在windows7上安装Nginx,然后部署Django的,过程中遇到了一些小问题,所以都记录下来!供以后查阅!几个细节的东西,有必要写清楚!官网上下载地址:http://nginx.org/en/download.html就那最新的版本做实验吧。我下了 windows原生版本 0.8.53,整个文件就是一个zip压缩文件。下载到C盘的根目录下,解压缩。出来的文件夹是nginx-0.8.53,顺便改成了nginx,方便使用(其实改不改都没有关系,改了,是因为重启nginx的时候,少打点字母罢了)。然后冲动的进入文件夹,双击启动文件nginx.exe,弹出了一个doc窗口,就在眨眼的功夫里,消失了,没有看清提示什么内容;不管三七二十一,我在浏览器了,打开127.0.0.1,提示 无法显示页面。我们没有安装IIS7,如果是无法显示页面,说明nginx启动失败了。但是到底是什么原因让nginx无法启动呢?我想个办法,放doc的提示显示出来,结果提示是:[emerg]:bind() to 0.0.0.0:80 failed <10013: An attempt was made to access a socket in a way forbidden by its access permissions>看提示信息,是因为windows 的80 端口被占用了,所以又想办法把80端口释放了,最终还是没有释放成功,windows把80端口保留给最底层的进程用了,释放80端口行不通,又想别的招。然后安装了IIS7,这时80端口自然就分配给IIS7了。IIS安装成功,然后把停止IIS7的运行,自然80端口就被闲置了。果真如上所说,80端口真的被释放了。然后双击nginx.exe来启动nginx,这回没有提示信息了,打开浏览器 127.0.0.1:80;呵呵,nginx终于正常运行。为什么要nginx运行在80端口上呢?因为本人想让nginx作为代理服务和前端服务。域名指向到服务器的ip的时候,直接就找到nginx。所以周折了一番。在配置django环境的时候,有遇到了问题。我明明修改了nginx.conf的参数了,在重新启动的时候,都是无效的,很是郁闷,所以django环境配置无法配置成功了。仔细检查了配置文件的语法错误,发现了一些错误,修改过来了,仍然无效,干脆恢复原来的配置文件,还是老样子,这么一来就奇怪了。压根重启是无效的。官方的文档很清楚:nginx -s stop quick exitnginx -s quit graceful quitnginx -s reload changing configuration, starting a new worker, quitting an old worker gracefullynginx -s reopen reopening log files就这么几行命令,执行后,一切都正常,就是没有效果。最后想到办法,打开windows的任务管理器,把nginx的几个进程都关闭了,启动nginx,终于看到想要的效果了。nginx对windows的支持还不算很好,有些东西还是很折腾。 -
Windows7+Nginx+Flup(fastgci)+Django
上回记录了Windows7配置了Nginx环境,这回让Django跑在Nginx上。之前是需要点理论知识沉淀的;建议之前看看:http://www.fresh3g.org/blog/post/346/ 感觉写的很详细。下面是根据那些理论知识去尝试配置环境:首先我们要做的是:安装及配置Django,Nginx和Flup;Django和Nginx环境配置不再累赘。请参考:http://baoyalv.com/blog/baoyalv/Django/2010/02/03/4和http://baoyalv.com/blog/panjj/other/2010/11/07/136;安装Flup,到官网上http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz下载,解压后发现是python写的类库,把它安装到python里,安装方法和其他的python类库一样做法,在doc命令行里执行:python setup.py install #注意要求python写到path里,才能有python命令过程中可能需要联机,因为安装的过程中需要下载一些相关的东西。接下来,1.配置Nginx,配置文件见以下代码:worker_processes 1;events {worker_connections 64;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 80;server_name 127.0.0.1;root /cygdrive/G/myproject/;index index.html index.htm;charset utf-8;# 静态资源location ~ ^/static/{expires 30d;break;}location / {# 指定 fastcgi 的主机和端口fastcgi_pass 127.0.0.1:9001;fastcgi_param REMOTE_ADDR $remote_addr;fastcgi_param PATH_INFO $fastcgi_script_name;fastcgi_param REQUEST_METHOD $request_method;fastcgi_param QUERY_STRING $query_string;fastcgi_param CONTENT_TYPE $content_type;fastcgi_param CONTENT_LENGTH $content_length;fastcgi_param SERVER_PROTOCOL $server_protocol;fastcgi_param SERVER_PORT $server_port;fastcgi_param SERVER_NAME $server_name;fastcgi_pass_header Authorization;fastcgi_intercept_errors off;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}}建议备份好原来的配置文件,然后再覆盖nginx文件。该配置文件只是实验用,连log都没有写,想了解更详细的文档,参考官方文档:http://wiki.nginx.org/DjangoFastCGI现在列出关键的几个地方:server {listen 80; #首先让Nginx跑在Windows的80端口上:server_name 127.0.0.1;#写上project对应的域名 我们在本地上测试,所以是127.0.0.1root /cygdrive/G/myproject/;#项目的根目录,在windows下,如果是G盘,写上/cygdrive/G/,依次类推。切忌不要写成G:\myproject\location ~ ^/static/ #静态文件指向,我们直接指向项目根目录的static文件夹,根据实际情况正确指向fastcgi_pass 127.0.0.1:9001;#我们通过fastgci(flup)在9001端口上跑django项目fastcgi_param REMOTE_ADDR $remote_addr;#加上这行,是因为django request用到获取真实ip的的属性,关键的地方都一一说明了,检查配置都写对后,重启Nginx,(记得任务栏里关掉全部nginx进程再重启)2 通过fastgci run django在doc里进入django项目的根目录,启动:manage.py runfcgi method=threaded host=127.0.0.1 port=9001也可以编写指令,方面启动:在项目的根目录下新建 一个vbs文件run:set ws=wscript.createobject("wscript.shell")ws.run "manage.py runfcgi method=threaded host=127.0.0.1 port=9001",0以后每次启动,双击run文件即可。现在在浏览器上,输入:127.0.0.1 是不是看到页面跑起来了?? -
Windows7安装Postgresql 8.4以上版本出错解决办法
在Vista或者Windows7上安装Postgresql 8.4或者Postgresql 9.0,到了最后的关头总是出错!提示错误信息是:database cluster initialization failed。也许很沮丧吧?但是看一下错误,就知道为什么了?今天来解决PostgreSql不能安装的问题:首先安装进度到了选择database cluster的时候,不要选择默认的选项:Default locale;随便选一个,推荐选择english en-us。然后一路安装过去,就能成功了。网络上说是权限问题,本人无从考证,如果以上设置还是没有安装成功的时候,你可以到安装遗留目录postgresql上,将此目录的权限赋给所有人,也就是everyone。最后把控制面板中的 User Account Control settings(UAC)的安全级别关闭,再试试。(完) -
在Django中使用CKEditor
在博客中使用富文本编辑器是很常见的,今天尝试在Django中使用比较知名的CKEditor。前提条件是通过静态文件的正确配置,可以参考之前写的《Django静态文件的配置》,今天不再累赘。一 前提条件:1. 找到第三方支持插件:django-ckeditor相关开源项目地址:https://github.com/dwaiter/django-ckeditor2. python中安装simplejson相关包地址:http://pypi.python.org/pypi/simplejson/安装方法和安装其他Python第三方库是一样的(下载该包,解压,到包的目录下,执行 python setup.py install,过程中python会自动寻找依赖的类库,所以你必须能连上网络)。二 配置CKEditor环境你可以选择把django-ckeditor安装到python里,也可以把下载的django-ckeditor作为自己的app来用。我选择后者。下载的django-ckeditor,目录结构:ckeditorsetup.py...把django-ckeditor里的ckeditor直接粘贴到我们的项目中,然后把该app的templates和media挪出来,整个项目的目录结构:app_test #这是我特意创建的一个自己的app,作为测试用。ckeditorstatic--|ckeditor----|...--|css----|...templates--|ckeditor__init__.pymanage.pysettings.pyurl.py整个过程就是把下载的ckeditor文件夹当成一个全新的app,熟悉的Django的就不必一一介绍了,如果你和我一样是新手,不用担心,我们教程后面有一个基本的实例 供参考。我们在settings.py最后一行,给ckeditor写一些配置:CKEDITOR_CONFIGS = { 'default': { 'toolbar':[ ['Source','-','Save','NewPage','Preview','-','Templates'], ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print','SpellChecker','Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form','Checkbox','Radio','TextField','Textarea','Select','Button', 'ImageButton','HiddenField'], ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['Link','Unlink','Anchor'], ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'], ['Styles','Format','Font','FontSize'], ['TextColor','BGColor'], ['Maximize','ShowBlocks','-','About'] ], 'width': 650, 'height': 200, 'toolbarCanCollapse': False, }, 'simple_toolbar': { 'toolbar': [ [ 'Bold', 'Italic', 'Underline' ], ], 'width': 650, 'height': 50, }, }一个是默认的配置,几乎是ckeditor的全部功能,一个是简单的配置,仅仅提供几个再简单不过的功能。更具体的配置参考CKEditor官方网站吧。三 使用CKEidor涉及到表单控件的,我们习惯使用Django的forms。我们在app_test里定义了一个forms类#coding=utf-8from django import formsfrom ckedj.ckeditor.widgets import CKEditor #ckedj是定义的项目名class BlogPostForm(forms.Form): title = forms.CharField() # This field will render as a CKEditor with the 'simple_toolbar' config. subtitle = forms.CharField(widget=CKEditor(ckeditor_config='simple_toolbar')) # … -
Django&JQuery手动剪切个性头像+实例
几个月前,尝试Django结合Jquery的jquery imgareaselect插件,对头像进行剪切。用的场合很特别,虽然用处不是很大,但有些朋友却要求提供此类应用的源码。想想,之前写的《Django&JQuery手动剪切个性头像》主要是原理性的东西,看着很抽象,片段的代码,难免造成困惑,所以想:何不把龅牙驴的头像剪切功能抽取出来,做个独立的学习实例呢?所以今晚专门赶出来了,但是很遗憾,学习实例并不是做成通用的Django插件,让读者即插即用。因为没有插件开发方面的经验和精力,所以还是做出一个app,没有考虑太多的通用性和扩展性,旨在学习,抛砖引玉!需要的朋友可以下载 源码,源码是完整的 project,包括静态文件的配置都全了,想学习Django静态文件配置的朋友,也可参考整个project。环境:Django 1.2.3+jquery.imgareaselect-0.9.3+SQLite3好了,如果源码有任何问题,请文章后面回复我,或者通过龅牙闲聊告诉我吧!应用截图: -
新手学Django
刚接触这个东西,不会用,不知道从什么地方下手 -
注册,登录
#coding=utf-8from django import formsfrom django.core .urlresolvers import reversefrom django.http import HttpResponse, HttpResponseRedirectfrom django.shortcuts import render_to_responsefrom django.template import RequestContextfrom django.contrib.auth.models import Userfrom django.utils.translation import ugettext_lazy as _from django.contrib.auth import authenticate, login as auth_login ,logout as auth_logoutdef index(request): '''首页视图''' pa = '' template_var = {} forme=(request.POST) if 'name' in request.POST and request.POST['name']: username = request.POST['name'] password = request.POST['pwd'] request.session['username'] = username ret = User.objects.get(username=username) ret2 = ret.check_password(password) # print ret2 if ret2: return HttpResponseRedirect(reverse("welcome")) else: pa = "用户名或密码错误" #return render_to_response("accounts/index.html",{'index':index, 'pa':pa}) if request.session['username']: username = request.session['username'] template_var["username"] = _(u"欢迎您 %s!")%username return render_to_response("accounts/index.html",template_var) #print forme'username' return render_to_response("accounts/index.html",{'index':index, 'pa':pa})def welcome(request): '''欢迎页面''' username = request.session['username'] template_var = {} template_var["username"] = username return render_to_response("accounts/welcome.html",template_var) # return render_to_response("accounts/welcome.html",{'welcome':welcome})def register(request): '''注册页面''' msg = '' error = '' if request.method=="POST": form=(request.POST) if 'name' in request.POST and request.POST['name']: username = request.POST['name'] password1 = request.POST['pwd1'] password2 = request.POST['pwd2'] if User.objects.filter(username=username): error = "用户名已经存在" #return HttpResponseRedirect(reverse("error")) return render_to_response("accounts/register.html",{'register':register, 'error':error}) if password1 == password2: useradd = User.objects.create_user(username,password1) useradd.set_password(password1) useradd.save() request.session['username'] = username return HttpResponseRedirect(reverse("welcome")) else: msg = "两次密码不一样" return render_to_response("accounts/register.html",{'register':register, 'msg':msg})def logout(request):# '''注销视图''' #auth_logout(request) #request.session.flush() #try: # username = request.session['username'] # del request.session['username'] #except KeyError: # pass # return HttpResponseRedirect(reverse('index')) return HttpResponseRedirect(reverse('index')) 我想做一个能把用户注销掉,不知道怎么做,请高手给我添加代码并,解释一下大概引用哪些函数,模块。 -
Django和Ajax的那些事儿-开篇
把Django和Ajax放在一起,那是很久远的事了,有人说在Ajax大紫大红的时候,Django错失了机会,没有把Ajax集成到自身,借助Ajax的这股东风传播自己。而如今有些人还觉得遗憾,但也有些人感到庆幸;说遗憾,那些人会指着Rails,说:看,Rails当年就是因为借助Ajax来让更多人认识到自己的...而觉得庆幸的人,心里想:Django掌陀人当年的决定,现在得到印证了,Ajax其实就是一门新新的技术,它应该由其他组织大力发展它,让它更加独立,更加强大,更加灵活,放之四海皆准。 个人觉得,Django还是继承了Python大道至简的理念,经纬分明。Ajax原本就不是Django所独有的,让它在技术领域上细分,竞争,变得更强大;这样其他程序框架会得益于Ajax,Django也会得益于Ajax;如果集成Ajax于一身,Django的Ajax会变得局限,Django的使用者看似有更好的发挥但仅仅限于Django的Ajax上。这和Django的Templates应不应该放些程序逻辑的事情有几分相似,程序员和页面设计师遇到这个问题,相信会有不同的意见,所以最后都采取了折中的解决办法。 这个问题暂且不谈论,让它智者见智,仁者见仁吧。 Django不会阻止我们去用Ajax,我们把所熟知某框架的Ajax用在Django也不见得是件难事,相反我们有自己的选择权,选择哪个js框架,Jquery也好,Dojo 、Scriptaculous 、Prototype 、yui-ext 、Mochikit、mootools也罢,只要我们有自己的选择标准足矣. 我不是个脚本师,偶尔看看Jquery的东西,Jquery里的内部机制原理一知半解,但我相信能在Django里用用Ajax的东西,想来Django也算厚道,照顾到我这样的人群了...^_^ -
Django上使用gravatar
gravatar是什么?从它的全拼字母A Globally Recognized Avatar来识别,大概可以理解为:全球公认的头像;全球认证的头像...你可以到gravatar官方网站上传自己的头像,然后到第三方网站上发帖留言写博客...这时网站上就显示你的头像了,前提条件是这个第三方网站必须支持gravatar应用才行,以下就是今天说的重点了:让自己的网站支持gravatar应用。说做法之前,我们顺便提些东西。gravatar应用的使用范围越来越广,你除了在gravatar官网上传自己的公认头像之外,你还可以在其他组织的Email上设置,比如在Google的Gmail里上传了头像,gravatar会找到Google上的头像标示你本人...因为gravatar关联的信息是你的Email。所以你的Email是关键所在。一 让自己的网站支持gravatar,有什么用?好吧,看来得说说gravatar的用途了。你也知道,不仅中国的网民,全球的其他网民(可能会好点)都喜欢免费的午餐,感兴趣的东西喜欢看看,喜欢说点什么,但非要注册后才能看才能发言的话,他们宁愿溜之大吉...站长已经司空见惯,应该接受事实,所以干脆给这些可爱的人更大的空间,让他们和自己的会员一样,能看他们喜欢的东西,能说说自己的见解,而无需注册成为自己的会员...随之的匿名访问,匿名评论应用红遍大江南北...那时,站长怎么给匿名用户保留个身份呢?嗯,留网站地址,昵称,Email,足够了;自从gravatar诞生后,匿名用户又拥有了自己的头像...^_^除了让匿名用户显示真实头像之外,其实还有很多用途,gravatar官网上说的很清楚,E文可以的,去看看吧:http://cn.gravatar.com/通俗来说,就是Email和真实头像直接挂钩。如果站长足够灵活,可以不用做用户的头像上传应用,直接用gravatar实现相似的功能了。二 怎么让自己的网站支持gravatar?好吧,说说gravatar官方的做法,gravatar支持的开发语言很多种,同样Djanog也得到了支持,官方推荐使用tag的方法。代码如下:### gravatar.py ################## place inside a 'templatetags' directory inside the top level of a Django app ###(not project, must be inside an app)### at the top of your page template include this:### {% load gravatar %}### and to use the url do this:### <img src="{% gravatar_url 'someone@somewhere.com' %}">### or### <img src="{% gravatar_url sometemplatevariable %}">### just make sure to update the "default" image path belowfrom django import templateimport urllib, hashlibregister = template.Library()class GravatarUrlNode(template.Node): def __init__(self, email): self.email = template.Variable(email) def render(self, context): try: email = self.email.resolve(context) except template.VariableDoesNotExist: return '' default = "http://example.com/static/images/defaultavatar.jpg" size = 40 gravatar_url = "http://www.gravatar.com/avatar/" + hashlib.md5(email.lower()).hexdigest() + "?" gravatar_url += urllib.urlencode({'d':default, 's':str(size)}) return gravatar_url@register.tagdef gravatar_url(parser, token): try: tag_name, email = token.split_contents() except ValueError: raise template.TemplateSyntaxError, "%r tag requires a single argument" % token.contents.split()[0] return GravatarUrlNode(email)tag的使用方法,就简单说说吧:Django的app上建立一个文件夹templatetags,里面放一个__init__.py文件(可以是空的),让templatetags成为python的一个包,然后建立gravatar.py文件,把以上的代码复制过去,准备工作就算完成了。在templates里使用,比如blog.html中,加入{% load gravatar %},装载gravatar的tag.这时blog.html能使用注册的gravatar_url方法了。如:<img src="{% gravatar_url c.email %}" alt=""/>给gravatar_url函数传入用户的email即可解析到该email相对应的头像地址。使用官方的代码,值得注意的是,需要修改些代码,请把default = "http://example.com/static/images/defaultavatar.jpg"修改成 真实的地址,如果你网站上有默认的头像,请附上真实的地址,不然gravatar发现该email没有上传头像时,就解析不出gravatar的头像地址了。如果你网站没有所谓默认的头像,建议拿掉default参数;把gravatar_url += urllib.urlencode({'d':default, 's':str(size)})改成gravatar_url += urllib.urlencode({'s':str(size)})。还有就是size = 40,是显示头像的大小,单位是像素。官网建议tag的用法,只要我们摸索了gravatar做法,也可以使用filter的方法,我们自己在gravatar.py底下写几行代码就可以搞定了:@register.filter def get_gravatar(email): return "http://www.gravatar.com/avatar/" + hashlib.md5(email.lower()).hexdigest()+'.jpg?s=40'templates上的用法:<img src="{{c.email|get_gravatar }}" alt=""/>好像没有什么东西说的了,必要加上gravatar应用的同学,可以试试... -
架设在GAE上的博客程序
架设在GAE上的博客,大概有近十种,micolog、pyweblog、n23、xian-min、tublog、pblog等。我通通下载安装试用了一遍,最后排除了所有,只剩下micolog。其它博客的优缺点如下,好坏不分先后: Pyweblog 演示:http://plog.appspot.com/ 代码:http://code.google.com/p/pyweblog/ 优点:界面清爽,写文章、管理、评论功能完备,支持上传,无任何广告 缺点:不支持导出导入 Cpedia 演示:http://blog.cpedia.com/ 代码:http://code.google.com/p/cpedialog 优点:页面设计非常强大,界面清新,功能完善,后台可以拖动设置主页各模块位置。 缺点:过于臃肿,近7M;嵌入难以去除的广告,需手动去除;不支持导出导入。 n23 演示:http://n23.appspot.com/blog 代码:http://code.google.com/p/n23/ 优点:测试未成功,页面混乱; 缺点:过于臃肿,达7.8M; xian-min 演示:http://xian-min.appspot.com/ 代码:http://code.google.com/p/xian-min/ 优点:程序简约,仅几百K;最基本发文章、修改删除文章功能,评论功能。 缺点:过于简单,甚至没有文本编辑器,不支持导入导出 tublog 演示:暂无 代码:http://code.google.com/p/tublog/ 优点:绝对精简,发文章管理评论均有,不错的编辑器;注意后台是/admin,主页无链接;无任何广告 缺点:精简不会成为它的缺点,它就是这样;不支持导入导出 potlatchblog 演示:http://aaronspotlatch.appspot.com/ 代码:http://github.com/araddon/potlatchblog/tree/master 优点:发文章、管理评论等基本功能均有,注意后台是/admin,主页无链接;无任何广告 缺点:未排版,无特殊之处;不支持导入导出 niub 演示:http://niubi.appspot.com/ 代码:http://code.google.com/p/niubi/ 优点:暂无,运行出错 缺点:程序非常大,17M; onlypy 演示:http://onlypython.appspot.com 代码:http://code.google.com/p/onlypy/ 优点:界面非常整洁,功能完备。 缺点:程序非常大,18M;过多作者信息 i-here 演示:http://ihere.appspot.com/blog/ 代码:http://code.google.com/p/ihere-blog/ 优点:作者热情,很有前途;界面简约、功能完善;支持兼容wordpress导入导出;支持多人协作;可以修改文章发布时间;支持Live Writer发布;支持上传;支持Development Console可视化查看后台数据库、流量;支持URL重定向;无任何广告 缺点:程序过大,11M,但支持这么多功能,大些是可以理解的 看了这么多优秀的博客程序,如果不是因为micoblog的简约和兼容,我肯定选择了i-here。不过我最早接触micoblog,给我留下了很好的印象。此外本博客使用vvonder修改完善的micoblog版本,功能多了不少,界面也更好看。 micolog 演示:http://xuming.net 代码:http://code.google.com/p/micolog/ 优点:界面清新,程序精简(仅800K),发文章、管理、评论、Tags、分类等都和上面大部分博客一样非常完备;后台管理界面友好,支持RSS,支持Wordpress格式导入导出;容易修改移植Wordpress主题;支持上传文件;支持Live Writer发布;无任何广告;作者热情,用户量较大 缺点:比较一下i-here,我个人非常需要它的修改文章发布时间的功能,虽然我可以通过导出–修改–导入的方式达到目的;不支持多人协作 就是从这些博客的应用里,我看到了Google App Engine和Python的好玩之处。上个月我开始学习Python,我还需要学习一下Google APP和Django等这些开发文档。我想在一两个月内,完善micoblog,实现我需要的功能。对于micolog,我还希望得到一下一些功能: 导出时支持将图片备份至本地,同样支持将备份图片还原 加入验证码 可拖动设置主页模块 插件支持,如Twitter等 在线换肤 在线升级 我收藏的几个使用micolog的网站 http://vvonderblog.appspot.com/ http://www.houkai.com/ http://www.kgblog.net/ 来源:http://www.pugwoo.com/2009/11/12/choose-micolog-new-begin.html -
粗略记录祖宗往事
这次回去,很多事情忙,一个大家庭的成员都回来差不多了,小孩和老人相差将近80年!和自己年龄相近的人都认识,唯些许小孩和老人都不识面了,因为我出来的时候,有些小孩没有出生,而自己小的时候也很少见到远门的老人们。几十年的历史,不是我所能认识的了,离家的时候,爷爷还健在,奶奶也还硬朗,如今爷爷去了,年长的只剩下奶奶!眼前的情景,不知道拿什么来形容。吃完晚饭仔细端详了一下奶奶,古铜色的脸爬满了皱纹,脸上的黑斑记录着逝去的岁月!那逝去的年月,我想该是要粗略记下来了,为了尽量保持历史的真实性,开始克制自己急迫的情绪,保持平静的心情,也让奶奶静下来,把那段近百年的往事娓娓道来。可惜没有完成预期的任务,说到过去的事情,奶奶始终没有办法平静下来,因为没有太多的事情在她人生经历和知识看来是理解不了的,还有段时期她还不在场,后面也是老人们讲述的。致使记录带些个人情感和不真实的元素,但我实在找不到真实的线索了!不如把她说的都记录下来。 我们村(欧村)最初是在桂平往下的一个村庄(假名 牛麻)迁徙过来的,原因不详。祖先可能后来有了两个儿子,结果分东西两边,一个住在东边一个住在西边。我家族分支在东边;后来村子发展道了一百多人,又有一两家人搬进来了,原先是姓 马,后面未知原因也改姓 潘了,可能是为了更好的相处的缘故吧! 我家的太爷爷的爸爸,28-30岁中途夭折(在桂平去世),当时太爷爷还小。成年后,娶了石龙白糖的太奶奶。太爷爷和太奶奶那时大概在鸦片战争时代,当时鸦片在村里毒害了很多祖先,包括太爷爷也有烟瘾,太爷爷应该有三个兄弟,形成了三个分支,也就是村里东边最大的三个分支,育期是太三奶奶分支的,业幸估计是太大爷爷分支的,我便是二分支的了。我的太爷爷中年时开始吸鸦片,酗酒。太奶奶喜欢干净,很少去料理农活。两人有四子三女,由于晚期的衰落,爷爷的两个兄弟被贩卖到厚陆..只剩下爷爷和小爷爷他们,至于三个姑婆出嫁不详。太爷爷享年53,太奶奶享年93左右,是村里最长寿的一个老人之一。爷爷20岁左右,娶了一门妻,由于长年在外,妻子改嫁(奶奶说被太奶奶贩卖了),后来爷爷34岁左右,娶了奶奶,两人年龄间隔11岁,奶奶是普平的陆村人。两人一共有三儿两女,两女现在广东,大姑姑生于1959年,先嫁如玉林地区,后来一家迁徙到广东。小姑生于1966年,嫁如广东地区,有两儿;我爸是长子,生于1953年,妈妈是石龙良山人(原先是庆丰黄村人,家里有两个哥哥,三个姐姐,二姐嫁个石龙白洞,大姐姐嫁个石龙良山,也是妈妈的养家,大姐姐既是妈妈的大姐也是养母,也就是我现在的外婆,外婆无嗣,领养了外公小弟的四儿子为子,我妈妈是养长女,还有一个养女,也出于外公小弟的女儿。外公三兄弟)。爸爸妈妈有两儿两女,大姐嫁到广东化州地区,二姐加入石龙白糖,大哥20岁娶妻,现有两子,无女。我和业幸是村里的早年出去的大学生,高中均在桂平浔高就读,三年后,业幸考进广西大学,而我就读于内蒙古的一所学校,我于2011年结婚,妻子是庆丰林桥大竹园村人,尚未有子。大姐两女一儿,儿子排名第二。二姐一子一女。 爷爷享年88岁,于1999年家里去世,父亲1953年生,早年马车做运输,中途卖过猪肉,后来改回运输,开过手扶拖拉机,和小货车,中年1993年不幸染疾去世,终年40.二叔生于1955年,从事渔业,承包村里的池塘养鱼,家有两儿三女,大女儿是长女,嫁入广东地区,二女儿加入北流地区,小女儿未嫁。大儿子已婚,一女一子,小儿子未娶。二婶石龙龙山人。于1999年,二叔壮年染疾去世。小叔生于1967年,早年发酵豆芽,后期改行做烧鸭至今。小婶石龙白糖人,有一儿两女,儿子2010年结婚,在家族中排行老四,妻子石龙人。小叔大女儿现就读于桂林一所大学,小女儿初三。 小爷爷家族,有五儿一女!大儿子在柳州市,上门女婿;二儿子从医,中年娶妻,东北大同人,无嗣,有养女一个,现在南宁就读大学。三儿早期教师,先在广东惠州安家,从事建筑业,有一儿一女,女儿是长女,加入石龙普平。四儿子有两儿三女,五儿子有一儿两女,均未成年。 -
中国省市数据库表-MYSQL版
最近需求中国的省市表,找了半天,终于找到了一个mysql sql文件,先记下来,有空再转成postgresql版本的。 DROP TABLE IF EXISTS `province`; CREATE TABLE `province` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8; -- ---------------------------- -- Records of province -- ---------------------------- INSERT INTO `province` VALUES ('1', '北京市'); INSERT INTO `province` VALUES ('2', '天津市'); INSERT INTO `province` VALUES ('3', '上海市'); INSERT INTO `province` VALUES ('4', '重庆市'); INSERT INTO `province` VALUES ('5', '河北省'); INSERT INTO `province` VALUES ('6', '山西省'); INSERT INTO `province` VALUES ('7', '台湾省'); INSERT INTO `province` VALUES ('8', '辽宁省'); INSERT INTO `province` VALUES ('9', '吉林省'); INSERT INTO `province` VALUES ('10', '黑龙江省'); INSERT INTO `province` VALUES ('11', '江苏省'); INSERT INTO `province` VALUES ('12', '浙江省'); INSERT INTO `province` VALUES ('13', '安徽省'); INSERT INTO `province` VALUES ('14', '福建省'); INSERT INTO `province` VALUES ('15', '江西省'); INSERT INTO `province` VALUES ('16', '山东省'); INSERT INTO `province` VALUES ('17', '河南省'); INSERT INTO `province` VALUES ('18', '湖北省'); INSERT INTO `province` VALUES ('19', '湖南省'); INSERT INTO `province` VALUES ('20', '广东省'); INSERT INTO `province` VALUES ('21', '甘肃省'); INSERT INTO `province` VALUES ('22', '四川省'); INSERT INTO `province` VALUES ('23', '贵州省'); INSERT INTO `province` VALUES ('24', '海南省'); INSERT INTO `province` VALUES ('25', '云南省'); INSERT INTO `province` VALUES ('26', '青海省'); INSERT INTO `province` VALUES ('27', '陕西省'); … -
中国省市数据库表-PostgreSQL版
昨晚发现了中国省市数据库表-MYSQL版,那时已经凌晨3点左右了,实在太困了,没有来得及转换成PostgreSql版本的!现在趁着刚起来,改了些sql,让它能在PostgreSql上执行,创建那两个省份和城市表。用法:首先需要在PostgreSql上创建一个数据库(可以随意命名),然后把以下的sql语句执行一遍,即可完成. -- Table: province DROP TABLE province; CREATE TABLE province ( id integer NOT NULL, "name" character varying(50), CONSTRAINT province_id PRIMARY KEY (id) ) WITH ( OIDS=FALSE ); ALTER TABLE province OWNER TO postgres; -- ---------------------------- -- Records of province -- ---------------------------- INSERT INTO province VALUES ('1', '北京市'); INSERT INTO province VALUES ('2', '天津市'); INSERT INTO province VALUES ('3', '上海市'); INSERT INTO province VALUES ('4', '重庆市'); INSERT INTO province VALUES ('5', '河北省'); INSERT INTO province VALUES ('6', '山西省'); INSERT INTO province VALUES ('7', '台湾省'); INSERT INTO province VALUES ('8', '辽宁省'); INSERT INTO province VALUES ('9', '吉林省'); INSERT INTO province VALUES ('10', '黑龙江省'); INSERT INTO province VALUES ('11', '江苏省'); INSERT INTO province VALUES ('12', '浙江省'); INSERT INTO province VALUES ('13', '安徽省'); INSERT INTO province VALUES ('14', '福建省'); INSERT INTO province VALUES ('15', '江西省'); INSERT INTO province VALUES ('16', '山东省'); INSERT INTO province VALUES ('17', '河南省'); INSERT INTO province VALUES ('18', '湖北省'); INSERT INTO province VALUES ('19', '湖南省'); INSERT INTO province VALUES ('20', '广东省'); INSERT INTO province VALUES ('21', '甘肃省'); INSERT INTO province VALUES ('22', '四川省'); INSERT INTO province VALUES ('23', '贵州省'); INSERT INTO province VALUES ('24', '海南省'); INSERT INTO province VALUES ('25', '云南省'); INSERT INTO province VALUES … -
我为什么热衷于PostgreSQL数据库
说这个问题的时候,我首先申明我并不是想挑起数据库谁优谁劣的无谓争吵;而是想说说,像我这样:平时工作大多使用MySQL MSSQL,而有独立博客的人,MySQL和PostgerSQL哪个是我比较喜欢的类型。MySQL和PostgerSQL两个数据库都是当前比较流行的开源数据库,尽管他们开源的标准不大一样,MySQL已经趋向于收费的状况,这说明它的市场占有率大,产品做的精良,背后有强大的靠山技术支持;而PostgerSQL也一直在平稳发展,在众多的社会开源开发者的努力下,版本已经到了9.0以上。一家强大公司内部研发和众多爱好者贡献代码支持,我更喜欢后者,我喜欢更纯粹的自由和共享。数据库很重要,我也很注重数据的导出导入这些备份功能,这方面MySQL做的很好,因为它的文档相当齐全,第三方的工具也很多,你有多种方式去做那方面的工作;PostgerSQL也有同样的功能,但本人的知识有限,不太会用Google,查到的文档都是几年前的东西,特别是中文方面的文档,很老的文档即使找到了,也并不是自己想要的。幸好有耐心看看官调的E文文档;目前为止只知道一两个备份的方法!但是如果自己有权限管理PostgerSQL服务器,一两个办法就已经足够了。MySQL分为好几种版本,犹如WINDOWS一样,分什么旗舰版,专业版,家庭版 服务器版...到了官网下载页面,天花乱坠的,不知道下载哪个。 PostgerSQL从某种程度来说,就一个版本。所有的功能都包囊在这个版本里,喜欢软件不分贵贱的。性能。额... 几年前,都说MySQL整体上会更快,现在呢?我也不知道,没有测试过。睁着眼睛说瞎话,像我这样在小井里的,感觉MySQL和PostgerSQL性能上没有什么明显的差别,我手头的都是小项目,做个商务网啦,做个博客啦 等等,并不知道他们的速度谁更快些?但有一次,自己的项目放在资源有限的服务器里,让我发现PostgerSQL让我等的时间,减少了,试了几次,结果还是一样。查询大量的记录,表现居然更明显;难道我没有优化MySQL,而产生的错觉?我也没有优化PostgerSQL呀!那过后,开始注意到PostgerSQL了。我喜欢物尽所用,花点钱买个内存才512M的虚拟的VPS,安装上python+nginx+PostgerSQL,让网站跑起来,包括Debian系统在内,所有内存占用不到一半;而改用MySQL,优化技巧有限,我到现在还没有办法做到PostgerSQL占用资源少的程度,即使我牺牲了一些有用的引擎,还是有点失望。PostgerSQL占用的内存少,稳定性会不会下降呢,使用了一年半载,你才能体会得到!PostgerSQL还是几年前他们说的那样,相当稳定啊...以下是本人是实际使用过程中,发现PostgerSQL的可爱之处...