Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfdb8a78

Browse files
authored
Update form.py
1 parentc846ae1 commitfdb8a78

File tree

1 file changed

+0
-37
lines changed

1 file changed

+0
-37
lines changed

‎PythonProject/form.py‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1 @@
1-
fromflaskimportFlask,render_template,request
2-
importsqlite3
31

4-
app=Flask(__name__)
5-
6-
# Database setup (creates the table if it doesn't exist)
7-
conn=sqlite3.connect('mydatabase.db')# Replace 'mydatabase.db' with your desired name
8-
cursor=conn.cursor()
9-
cursor.execute('''
10-
CREATE TABLE IF NOT EXISTS entries (
11-
id INTEGER PRIMARY KEY AUTOINCREMENT,
12-
name TEXT,
13-
email TEXT
14-
)
15-
''')
16-
conn.commit()
17-
conn.close()
18-
19-
20-
@app.route('/',methods=['GET','POST'])
21-
defindex():
22-
ifrequest.method=='POST':
23-
name=request.form['name']
24-
email=request.form['email']
25-
26-
conn=sqlite3.connect('mydatabase.db')
27-
cursor=conn.cursor()
28-
cursor.execute("INSERT INTO entries (name, email) VALUES (?, ?)", (name,email))
29-
conn.commit()
30-
conn.close()
31-
32-
return"Data submitted successfully!"# You might want a more sophisticated response
33-
34-
returnrender_template('form.html')
35-
36-
37-
if__name__=='__main__':
38-
app.run(debug=True)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp