に変換してください。私の質問を読んでいる間に間違いがありましたら、お詫び申し上げます。 私のウェブサイトでDjangoとPythonを使っています。テキストファイル内のデータを検索し、テーブルデータフレーム
私は2つの入力、input1、input2を取ることを読みたいディレクトリファイルを検索するために、ユーザーからの入力を読み取るプロセスが必要です。
キーワードが一致している場合は、変数にキーワードを設定します。次の行を出力します。
これはviews.py
def SearchBox(request):
fullpath = ""
input1= request.GET.get('input1')
input2= request.GET.get('input2')
input_combine = str(input1).upper() + "_" + str(input2)
summary = '1A'
search_string = 'delay_index_time'
if input_Lot is None:
return render(request, 'Output.html')
else:
path = "D:/file/" + str(input_combine) + "/" + summary
with open(path) as input_data:
for line in input_data:
if search_string in line:
context = {
"output": (next(input_data))
}
return render(request, 'Output.html', context)
テンプレートのHTML
で私のテキストファイル
delay_index_time 775435 delay_index_time 456345 delay_index_time 4567867867868 delay_index_time 567867
Pythonのコードです。
<form id = "lol" class="navbar-form navbar-left" role="search" method="GET" action=""> <div class="input-group"> <input style="left:260px; width:250px; top:-80px;" id="box1" name="input1" type="text" class="form-control" placeholder="Lot"> <input style="left:270px; top:-80px; width:250px;" id="box2" name="input2" type="text" class="form-control" placeholder="Operation"> <div style="left:540px; top:-101px;" class="input-group-btn"> <a href="{% url 'Output' %}"><button id = "search_sub" value="Search" class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button></a> </div> </div> </form>
{{ output|safe }}
{% endblock %}
私の問題は、それが唯一である出力の最初の行に印刷され:
しかし、他の3の出力に表示されていません。
EXTRA QUESTION
どのように私は私のウェブサイト上で1列にテーブル形式で出力表示をしたい場合。
NEW QUESTION
これは私のテキストファイル内のデータです。
- 私はIDユーザーである「ID_」を見つけた後、私は、文字列が表示されます。
- idユーザーを1つの列に表示します。
- 次に、idのユーザーの下に出力の次の行を表示するdelay_index_timeがあります。
- ただし、delay_indexの結果に複数の結果が含まれることがあります。
- 私はそれを2列の1つのテーブルにまとめます。
- チェックボックスを選択すると表示されます。ユーザーがユーザーIDだけを表示したいとすれば、そのユーザーIDは表示されます。ユーザーが両方のチェックボックスをオンにすると、両方のテーブルがテーブルに表示されます。
このチェックボックスについては、わかりません。申し訳ありませんが、私は質問の多くを求めている場合:(
id_A1 delay_index_time s_7754 s_7731 id_A2 delay_index_time mrs_7745 id_A3 delay_index_time s_77789 id_A4 delay_index_time s_7752
あるviews.pyこれは、これは私のテンプレート
context = {}
with open(path) as input_data:
for line in input_data:
if line.startswith('id_'):
if 'output' in context:
context['output'].append(line.lstrip('id_').rstrip())
if search_string in line:
if 'output1' in context:
context['output1'].append(next(input_data).lstrip('s_').rstrip())
context = {
'output': [(line.lstrip('id_').rstrip())],
'output1': [(next(input_data).lstrip('s_').rstrip())]
}
return render(request, 'Output.html', context)
の私の符号化です
<div class="container" style=" width:170px;"> <table style="" class="table table-bordered"> <thead class="success" > <th class="active"><b>Visual ID</b></th> {% for line in output1 %} <tr class="success"> <td>{{ line }}</td> </tr> {% endfor %} </thead> <thead class="success" > <th class="active"><b>Time Delay</b></th> {% for line in output %} <tr class="success"> <td>{{ line }}</td> </tr> {% endfor %} </thead> </table>
こんにちは、ありがとうございました。すべての出力を表示するコードは非常にうまく動作します。しかし、出力は表形式ではありません。 D –
テーブルの罫線については、CSSを使用してください。
–大丈夫サディア私はそれを得ました。あなたのお手伝いをありがとう:D –