質問編集履歴

1

一部解決したため

2023/01/13 09:04

投稿

shoshin-sha
shoshin-sha

スコア4

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
  そのテーブルの値を使用して、SQliteのデータを読みに行き(ここで、おそらくPythonに値を渡す)、
5
5
  iframeにデータを更新したく思います。
6
6
 
7
- ①:ボタンを押すと、Javascriptが実行され、inputボックスの値を取得
7
+ ~打ち消し線~~①:ボタンを押すと、Javascriptが実行され、inputボックスの値を取得~
8
8
  ②:値をPythonへ(flask)
9
9
  ③:PythonでSQliteに接続し、データを取得
10
10
  ④:同ページ内のiframe内のデータだけ書き換える(Tableデータ)
@@ -12,17 +12,24 @@
12
12
  できれば、ページは更新せず、iframe内だけ更新したく思います。
13
13
 
14
14
  ```input_box
15
- <h1>
16
- <input required type="text" class="data_base1" name="data_1" size="60" value="DateBase : {{title1}}">
17
- <input required type="text" class="data_base2" name="data_1" list="example1" size="60" autocomplete="off" value="">
18
- <datalist id="example1">
19
- {% for player in group %}
20
- <option value="{{ player }}">{{ player }}</option>
21
- {% endfor %}
22
- </datalist>
23
- </h1>
24
15
 
16
+ <input required type="text" class="data_base2" id="text2" name="data_1" list="example1" size="60" autocomplete="off" value="">
17
+
18
+ 省略
19
+
20
+ <div class="botton2">
21
+ <input type="button" class="botton_size" value='ページ更新' onclick="clickBtn1()" />
22
+ </div>
23
+
24
+ <script>
25
+ function clickBtn1() {
26
+ const t1 = document.getElementById("text2").value;
27
+ <!-- document.getElementById("text1").value = t1;-->
28
+ }
29
+ </script>
25
30
  ```
31
+ ↑上記でjavascriptよりinput boxの値は取得できました。
32
+
26
33
  ```Table
27
34
  <table class="editable-table border="1" style="text-align: center;vertical-align:middle;">
28
35
  <thead>
@@ -50,7 +57,96 @@
50
57
 
51
58
  ```
52
59
 
53
- ```ここに言語を入力
60
+ ```app.py
61
+ from flask import Flask, render_template, request, session, url_for, redirect, jsonify,g
62
+ from flask.views import MethodView
63
+ import sqlite3,pickle
64
+ import pandas as pd
65
+
66
+ app = Flask(__name__)
67
+
68
+ data_base="◎.db"
69
+ table_1="◎"
70
+
71
+ app = Flask(__name__)
72
+
73
+ def get_db():
74
+ if 'db' not in g:
75
+ g.db = sqlite3.connect(◎◎)
76
+ return g.db
77
+
78
+ def close_db(e=None):
79
+ db = g.pop('db', None)
80
+
81
+ if db is not None:
82
+ db.close()
83
+
84
+ #「/」へアクセスがあった場合に、"Hello World"の文字列を返す
85
+ @app.route("/")
86
+ def hello():
87
+ return render_template('index.html')
88
+
89
+ @app.route("/next_page", methods=['POST'])
90
+ def index():
91
+
92
+ global id2_
93
+ global id_
94
+ global path_
95
+ global db
96
+ global q1
97
+
98
+ if request.method == 'POST':
99
+ id2_ = request.form.get("user_id2")
100
+ id_ = request.form.get('user_id')
101
+ path_ = request.form.get('path1')
102
+
103
+ db = get_db()
104
+ sql = "SELECT name from sqlite_master where type='table';"
105
+
54
- コード
106
+ try:
107
+ cur = db.execute(sql)
108
+ except:
109
+ return render_template('/next_page.html')
110
+
111
+ q1=[]
112
+
113
+ for a in cur.fetchall():
114
+ q1.append(''.join(a))
115
+
116
+ return render_template('/next_page.html',title1=id_,title2=id2_,group=q1)
117
+
118
+ else:
119
+ return render_template('index.html')
120
+
121
+ @app.route("/hoge")
122
+ def next_page2():
123
+
124
+ V2 =id2_
125
+ V1 =id_
126
+
127
+ db = get_db()
128
+
129
+ mydata = []
130
+ sql = "select * from " + V2
131
+
132
+ try:
133
+ cur = db.execute(sql)
134
+ except:
135
+ return render_template('index.html')
136
+
137
+ mydata = cur.fetchall()
138
+ df=pd.read_sql(sql,g.db)
139
+
140
+ return render_template('/next_page2.html',\
141
+ title1=V1, \
142
+ title2=V2, \
143
+ group=q1, \
144
+ col_1=df.columns, \
145
+ num=mydata[0], \
146
+ data=mydata)
147
+
148
+ #app.pyをターミナルから直接呼び出した時だけ、app.run()を実行する
149
+ if __name__ == "__main__":
150
+ app.run(debug=True)
55
151
  ```
56
152