私信  •  关注

01071028

01071028 最近创建的主题
01071028 最近回复了
11 年前
回复了 01071028 创建的主题 » 求助:python下载远端服务器上的文件,paramiko安装问题

最终还是用pycrypto 2.1解决了问题。 需求实现方法: WEB客户端点击页面链接 ==》python用paramiko模拟SSH连接,到远程LINUX服务器上下载文件到WEB服务器上 ==》将刚刚下载到WEB服务器上的文件用URL组织起来,如/site_media/temp/test.tar.gz ==》return HttpResponseRedirect('/site_media/temp/test.tar.gz') ==》WEB客户端看到的是另存文件的对话框

以上可实现需求,不知是不是这种方法笨了点,走了弯路?

另外,问: python使用wget是不是还需要安装其它的东西?因为wget毕竟不是python的内库呀。

11 年前
回复了 01071028 创建的主题 » 询问一下有关django-pagination性能问题

之前我也遇见过这种问题,后网上查是说django paginator性能确实很差。 后来我只好从数据库SQL下手,每次查询一页的数据(50条)给paginator。 同时给查询的结果数也给paginator以便正确分页。

paginator = Paginator(res_log, perpage, search_num)

参考: 改造django paginator http://2goo.info/blog/panjj/Django/2012/11/18/545

11 年前
回复了 01071028 创建的主题 » django 中间件问题

问题终于解决了。谢谢楼上。 我是直接到Django中的HttpResponse中调试出来的。它执行到了HttpResponse。 修改代码:

class SessionExpiredMiddleware(object):
    def process_request(self,request):
        if 'last_activity' in request.session:
            last_activity = request.session['last_activity']
            now = datetime.datetime.now()

            if not request.is_ajax():
                # don't set this for ajax requests or else your
                # expired session checks will keep the session from
                # expiring :)
                # 系统时间AJAX显示不加入考虑
                if (last_activity + datetime.timedelta(minutes=30)) < now:
                    if 'user_name' in request.session:
                        del request.session['user_name']
                    if 'last_activity' in request.session:
                        del request.session['last_activity']
                    error_info = u'登录超时请重新登录'
                    logging.info('Login session expired!')
                    return render_to_response("framework/out_frame.html",{'error_info':error_info})
                else:
                    request.session['last_activity'] = now

        return None

原因是:在页面上我用AJAX做了个显示服务器时间的功能,所以它每秒都会request一次。 超时时,它已经response("framework/out_frame.html“)了。所以后面我再手动执行request,就没啥反应了。现在代码改为上面的,可以达到我的要求了。 只是那个显示时间的AJAX明明response了,还是没显示out_frame.html可能是我其它程序有问题。

谢谢!

11 年前
回复了 01071028 创建的主题 » django 中间件问题

删除 • Reply • 3 楼 01071028 0 分钟前

from django.template.loader
import get_template from django.template
import Context from django.http 
import HttpResponse 
t = get_template('framework/out_frame.html') 
c = Context({ 'error_info':error_info }) 
html = t.render(c) 
logging.info(html) 
try: 
    return HttpResponse(html) 
except Exception,e:
    logging.info('fail') 
    logging.info(e)

我换成httpresponse去输出了,没有抛出异常,连‘fail’那行都没执行。 按BeginMan说的我去捕获render_to_response的异常,也同样的结果,捕获不到。 分流又是什么意思呢?我应该怎么去调试?