import time
import secrets
from flask import Flask, render_template, request, redirect, url_for, session
import datetime
app = Flask(__name__)
app.secret_key = secrets.token_hex(16)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/admin', methods=['GET', 'POST'])
def admin():
if 网页链接 == 'POST':
password = request.form['password']
if password == '114514':
session['authenticated'] = True
return redirect(url_for('admin_page'))
else:
time.sleep(3)
return redirect(url_for('admin'))
return render_template('admin_login.html')
@app.route('/admin_page')
def admin_page():
if not session.get('authenticated'):
return redirect(url_for('admin'))
file_path = 'D:/GuangBo/songs.txt'
with open(file_path, 'r') as file:
songs = file.readlines()
date = datetime.date(2023, 9, 28)
weekday = date.strftime("%A")
return render_template('admin.html', songs=songs, weekday=weekday)
@app.route('/submit_song', methods=['POST'])
def submit_song():
song = request.form['song']
year = '2023'
month = request.form['month']
day = request.form['day']
file_path = 'D:/GuangBo/songs.txt'
with open(file_path, 'a') as file:
file.write(f"{song} - ({year}-{month}-{day})\n")
return redirect(url_for('song'))
@app.route('/contactUs')
def contact_us():
return render_template('contactUs.html')
if __name__ == '__main__':
app.run()
import secrets
from flask import Flask, render_template, request, redirect, url_for, session
import datetime
app = Flask(__name__)
app.secret_key = secrets.token_hex(16)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/admin', methods=['GET', 'POST'])
def admin():
if 网页链接 == 'POST':
password = request.form['password']
if password == '114514':
session['authenticated'] = True
return redirect(url_for('admin_page'))
else:
time.sleep(3)
return redirect(url_for('admin'))
return render_template('admin_login.html')
@app.route('/admin_page')
def admin_page():
if not session.get('authenticated'):
return redirect(url_for('admin'))
file_path = 'D:/GuangBo/songs.txt'
with open(file_path, 'r') as file:
songs = file.readlines()
date = datetime.date(2023, 9, 28)
weekday = date.strftime("%A")
return render_template('admin.html', songs=songs, weekday=weekday)
@app.route('/submit_song', methods=['POST'])
def submit_song():
song = request.form['song']
year = '2023'
month = request.form['month']
day = request.form['day']
file_path = 'D:/GuangBo/songs.txt'
with open(file_path, 'a') as file:
file.write(f"{song} - ({year}-{month}-{day})\n")
return redirect(url_for('song'))
@app.route('/contactUs')
def contact_us():
return render_template('contactUs.html')
if __name__ == '__main__':
app.run()