Django后台展示(二)

行云流水
2023-02-21 / 0 评论 / 123 阅读 / 正在检测是否收录...

说明

需要通过后台直接周期任务运行的结果日志,这样就不需要每次登录服务器。

代码

接口代码

def getlog(request):
    '''
    日志查看
    '''
    if request.method == 'GET':
        logpath = request.GET.get('path', default='')

        content = '无日志'
        if os.path.exists(logpath):
            with open(logpath, 'r') as f:
                content = f.read()

        return render(request, 'logview.html', {'logpath': logpath, 'content': content})

模板文件

{% block content %}
<h2>{{ logpath }}</h2>
<div style="background-color: black;color: azure" >
    <span  style="font-size: 10px"><pre>{{ content }}  </pre>
</div>
{% endblock %}

评论 (0)

取消
只有登录/注册用户才可评论