-2
from flask import Flask, render_template,request,url_for,make_response,redirect,session
from bs4 import BeautifulSoup
import sqlite3
import random
import models
import os
import socket
app = Flask(__name__)
app.config['SECRET_KEY'] = b"HelloWorld"
def check_session():
try:
loggedin = session['loggedin']
except:
session['loggedin'] = False
loggedin = session['loggedin']
return loggedin
@app.route('/')
def index():
loggedin = check_session()
#loggedin = True
blogpost = models.Blogpost()
posts = blogpost.conn.execute("SELECT path FROM posts ORDER BY timestamp DESC")
post_content = []
for post in posts:
post_text = BeautifulSoup(open(post[0],'r').read(),'html.parser')
post_content.append(post_text)
return render_template('home.html',loggedin=loggedin,post_content=post_content)
#return "HelloWorld"
@app.route('/login',methods = ['GET','POST'])
def login():
if request.method == 'GET':
return render_template('login.html',strike=0)
elif request.method == 'POST':
username = request.form['username']
password = request.form['password']
user = models.User(username)
result = user.authenticate(username,password)
if result == False:
session['loggedin'] = True
session['username'] = username
return render_template(home.html, session['loggedin']
if socket.gethostname() == "DESKTOP-D18" :
if __name__ == '__main__':
app.secret_key=1
app.run(host=os.getenv('IP', '127.0.0.1'),port=int(os.getenv('PORT', 8080)),debug=True)
else :
if __name__ == '__main__':
app.secret_key=1
app.run(host=os.getenv('IP', '0.0.0.0'),port=int(os.getenv('PORT', 8080)),debug=True)
これは私のフラスコアプリです。私はそれを実行すると、次のエラーが返されます: key: expected bytes or bytearray, but got 'int'
キー:予想されるバイトまたはバイトで、「int」を取得しました