前后端分离实现django日志下载,celery日志下载

djang后台:

# django日志下载接口
def django_journal_load(request):
    print BASE_DIR
    file = open(BASE_DIR + 'logsdjango.log', 'rb')
    response = StreamingHttpResponse(file.read())
    response['Content-Type'] = 'application/octet-stream'
    response['Content-Disposition'] = 'attachment;filename="{0}"'.format('django.log')
    return response


# celery日志下载接口
def celery_journal_load(request):
    file = open(os.getcwd() + '\..\task_centercelery.log', 'rb')
    response = StreamingHttpResponse(file.read())
    response['Content-Type'] = 'application/octet-stream'
    response['Content-Disposition'] = 'attachment;filename="{0}"'.format('celery.log')
    return response

html前端:

<dd><a href="" id="django_log">Django日志下载</a></dd>
<dd><a href="" id="celery_log">Celery日志下载</a></dd>

js

    var django_l=ip_number+"Django_journal_load";
    $("#django_log").attr("href",django_l);
    var celery_l=ip_number+"Celery_journal_load";
    $("#celery_log").attr("href",celery_l);
原文地址:https://www.cnblogs.com/qxh-beijing2016/p/12131830.html