Archive for web-2

没写完,先这样吧,应该要停写一段时间,先放出来。我又开始研究别的了0 0,golang又要放下了,不过我觉得,那个消耗的时间不会长,回头再接着写^_^. 我的第一个web框架,用go写。虽然没啥价值^_^ 靠,忘记写地址了0 0:github

Continue

在工作时服务器上环境的搭建,做个笔记记录。用到的东西主要有:django,nginx,supervisor,Gunicorn,virtualenv,mysql。 安装就略过了,每一个的文档上有介绍。virtualenv有一个virtualenvwrapper方便操作。 先安装virtualenv,然后在python虚拟环境里边安装django,gunicorn等相关库。 supervisor用来守护django网站启动的进程,默认配置文件添加/etc/supervisor/conf.d/name.conf

[program:code]
command=/home/sys/.virtualenvs/%(program_name)s/bin/gunicorn %(program_name)s.wsgi:application -c /home/www/%(program_name)s/%(program_name)s/gunicorn.conf.py
user=hg
directory=/home/www/%(program_name)s
autostart=true
autorestart=true
redirect_stderr=True
gunicorn.conf.py就是启动django的一些参数,制定监听的端口bind = "127.0.0.1:9006"。然后在nginx配置文件里边,进行转发。
server {
listen        80;
set $name "code";

server_name  code.xx.com;

root   /home/www/${name}/root;
access_log  /var/log/nginx/${name}.access.log;

location ~ (\.hg|\.orig|\.bak) {
deny all;
}

location /static/ {
expires max;
access_log off;
alias /home/www/${name}/static/;
}

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass   http://127.0.0.1:9006;
}
}
supervisor的一些命令: 修改配置文件以后要使用supervisorctl update命令,否则不会更新。刚开始的时候,捣鼓了好长时间 才知道要这样搞0 0. supervisorctl start all启动所有进程, supervisorctl start code 单独启动code进程。 使用supervisorctl可以进入管理程序。

Continue

0 0,今天用到redirectview,查文档,发现在django1.6版本可以直接指定pattern_name参数来直接指定跳转的url,方便了好多0 0.以前很讨厌在url里引用一大堆东西,我都尽可能写在views里边,至少看起来清楚。 下面有介绍get_redirect_url()只有在url没有设置的时候才会用到pattern_name。doc:https://docs.djangoproject.com/en/1.6/ref/class-based-views/base/#redirectview

Continue

配置的官方文档:http://docs.mongoengine.org/en/latest/django.html,安装的过程就不记了。 主要碰到的问题: 在按照文档配置完settings.py后,我写了登录代码。发现提示错误: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details. 这个明显说databases配置错误。但是我准确对照配置没问题,然后从网上找资料也没有结果。 然后我又看mongoengine里面的auth,还是不知道问题在哪里。然后我又找django的auth模块,突然想到: 肯定是调用这里出的错啊,然后我看浏览器显示错误的backtrack。 /usr/local/lib/python2.7/dist-packages/django/contrib/auth/views.py in login

    current_site = get_current_site(request)
啊哈,还是思路不清晰,瞎找。然后吧INSTALLED_APP里面的django.contrib.sites注释掉,成功。

Continue

以前都是用的django定义的user model,不用的字段也都这么放着,显然很不科学。 今天就看着一下文档,找到了方法,但是还是没用。。 https://docs.djangoproject.com/en/1.5/topics/auth/customizing/ 最彻底的修改settings的auth_user_model来指定user的model。

Continue

今天有想着瞎折腾了,帮老师改毕业设计还早着,但是实在不想写,可能因为感冒不爽。还是对不了解的东西感兴趣,然后开始了。 找到两个库,cl-http和hunchentoot,一个重量级,一个轻量级。选择后者了,因为只是想玩玩,写的代码肯定helloworld水平,just do it。 主要参考文章:http://blog.csdn.net/cx1468059916/article/details/8262515很详细 1.安装sbcl,执行命令:sudo apt-get install sbcl,sbcl好像是开源里边最受欢迎的。 2.安装quicklisp,是进行库管理的,方便安装。 下载quicklisp。wget http://beta.quicklisp.org/quicklisp.lisp 进入sbcl,载入:* (load "quicklisp.lisp") 安装(quicklisp-quickstart:install) 每次启动sbcl,载入sbcl,(ql:add-to-init-file) 安装库:(ql:quickload "system-name") 在命令执行过程中会有提示。 3.安装hunchentoot:* (ql:quickload "hunchentoot")其中安装了好多依赖库, 安装html-template:* (ql:quickload "html-template") 4.写程序:

(asdf:oos 'asdf:load-op :hunchentoot)
(asdf:oos 'asdf:load-op :html-template)
(defun myserver ()
  (hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port 8080))

  (hunchentoot:define-easy-handler (greet :uri "/hello") ()
                    (setf (hunchentoot:content-type*) "text/html; charset=utf-8")
                    (with-output-to-string (stream)
                       (html-template:fill-and-print-template
                        #p"hello_world.html"
                        ()
                        :stream stream))))
5.运行: * (load "hello_world.lisp") * (myserver)

Continue

需要一个settings文件template-context-processors的配置:https://docs.djangoproject.com/en/1.5/ref/settings/#template-context-processors官网文档有默认配置,本身生成的settings文件没有这个定义,使用默认配置。 然后多添加一行:

'django.core.context_processors.request',

就ok了
 

Continue

错误主要是在forms.py里面,想添加text文本编辑框,然后写了一个forms.TextField().....这不是重点,重点是我把views里的代码也写完,访问调试的时候,django页面提示View does not exist in module news.views。 views.py文件是一定存在的,不知道错在哪里。googel关键字找到so上说,用manage.py shell会提供更多信息。然后我再shell里导入views ,发现报前边的错误。修改,运行,然后正常了。

Continue

老师说要实现一个在线c语言学习的网站,引导用户一步一步编程。 找到这个网站:http://www.codecademy.com,准备以这个网站为原型设计。这个也不错http://www.paomianba.com/astar/ 需要一个一步一步的引导语,一个代码框,再一个代码保存的功能。代码运行这个先不考虑,安全性我还没考虑好。 加入用户登录功能,记录学习进度。加入每个步骤的提问,评论功能。 后台能够添加教程。 难度主要在代码输入编辑框中后,检测输入是否正确。 代码框准备使用http://ace.ajax.org/。前端使用js与服务器进行数据交互,判断是否正确。 后台代码用python写,框架不准备用django了,笨了点,使用tornado或者web.py,这两个文档都有看,就是没有实践一下了。数据库还是用mysql,查查资料,看看换个,借机学学其他数据库。

Continue

需要定时把一些数据表备份,并做数据统计。

$dates=date('Ymd',time());

//player表的备份
$newtable = "PlayerLog" . $dates;
$sql = "CREATE TABLE ".$newtable." LIKE game_qd.Player";
$linelist = $logdb->exec($sql);
print_r($linelist);
echo "\n\r\n";
$sql2 = "INSERT INTO ".$newtable." SELECT * FROM game_qd.Player";
$linelist = $logdb->exec($sql2);
print_r($linelist);
echo "\n\r\n player done";
,主要的代码就两行。 还学会了left  join的用法,当时没想到,是解决了判断一个备份表里有,另一个备份表里没有是计算差值时的问题。  
	
$sql7 = "select a.PlayerID,a.Score,(a.Score-IFNULL(b.Score , 0)) as Scorecha from ".$formtable." as a left join ".$endtable." as b on a.PlayerID=b.PlayerID order BY Scorecha desc,Score desc limit ".$limitnum;
.

Continue