首页 > 解决方案 > 使用刀片表单信息在 laravel 中运行 python 命令

问题描述

我正在尝试启动一个 python 脚本,其中一些信息存储在 laravel 5.6 中的表单中

该表格包含以下信息:

{!! Form::open(['action' => ['FormulaController@update', $formula->id], 'method' => 'POST']) !!}
  <div class="form-group">
    <div class="table-responsive">
      <table class="table">
        <tbody>
          <tr>
            <td>{{Form::label('tipo', 'Tipo Salida')}}
                    {{Form::select('tipo', ['int', 'float', 'booleano'], $formula->tipo_salida, ['class' => 'form-control', 'id' => 'tipo'])}}</td>
            <td colspan="2">{{Form::label('variables', 'Variables')}}
                    {{Form::text('variables', $formula->variables, ['class' => 'form-control', 'placeholder' => 'nox,/', 'id' => 'variables'])}}</td>
          </tr>
          <tr>
            <td colspan="3">{{Form::label('formula', 'Fórmula')}}
                        {{Form::text('formula', $formula->formula, ['class' => 'form-control', 'placeholder' => 'a*1', 'id' => 'formula'])}}</td>
          </tr>
          <tr>
            <td><h6>{{Form::label('Nombreresultado', 'Resultado:')}}</h6></td>
            <td>{{Form::label('resultado', $salida_formula)}}</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
<a href="/dahs/formulas/{{$formula->id}}" class="btn btn-primary">Back</a>
<input class="btn btn-primary" value="Evaluate" type="button"/>
{{Form::hidden('_method','PUT')}}
{{Form::submit('Guardar', ['class'=>'btn btn-primary'])}}
{!! Form::close() !!}

这个想法是,使用“评估”按钮,页面从表单的选择和文本中获取信息,并执行如下 python 脚本:

$/usr/bin/python /var/www/cgi-bin/evaluate.py 'nox_mgm3;float;a*1.881;nox,/'

我尝试了几种方法,直接在我的刀片模板、javascript、symfony 进程中使用 php 代码,但仍然发现这很奇怪,代码不好,或者可能不是“laravel 方式”

有没有这样的方法?还是我以这些方式中的某些方法是正确的?

此致

标签: phppythonlaravellaravel-5.6laravel-blade

解决方案


推荐阅读