【发布时间】:2019-11-28 03:03:20
【问题描述】:
我有一个名为 controlpanel 的页面,我可以在其中启动/停止脚本。当按下启动和停止脚本的按钮时,它返回相同的页面,按钮颜色更改,我想删除查询字符串。
view.py
def controlpanel(request):
data = {'paypal': paypal_, 'cpu': cpu_usage, 'active': active_task ...}
return render(request, 'admin/controlpanel.html', context=data)
def startapp(request):
if request.META['QUERY_STRING']:
#... start scripts etc..
request.META['QUERY_STRING'] = False
return controlpanel(request)
该函数返回带有查询字符串的控制面板...(127.0.0.1:8000/startapp?run=True 但我只想要 127.0.0.1:8000/控制面板)
controlpanel.html
<div>
{% if active %}
<button onclick="f()" class="btn btn-md btn-success">Start</button>
{% else %}
<button onclick="f()" class="btn btn-md btn-warning">Start</button>
{% endif %}
</div>
<script>
function f() {
let a = null;
if ('{{active}}' === 'True') {
a = 'stop'
} else {
a = 'start'
}
window.location.href = "/startapp?run=" + a;
}
</script>
【问题讨论】:
标签: javascript python django python-3.x