程式碼
""" from crypt import methods """
from email import message
from http import client
import collections
from lib2to3.pgen2 import driver
from unittest import result
import pymongo
client=pymongo.MongoClient("mongodb+srv://user:user123@new.ky4ln.mongodb.net/myFirstDatabase?retryWrites=true&w=majority")
db=client.member_system
print("連線成功")
from flask import*
app=Flask (
name,
static_folder="public",
static_url_path="/"
)
app.secret_key="any string but secret"
@app.route("/")
def index():
return render_template("index.html")
@app.route("/member")
def member():
if "nickname" in session:
return render_template("member.html")
else:
return redirect("/")
@app.route("/error")
def error():
message=request.args.get("msg","發生錯誤,請聯繫客服")
return render_template("error.html",message=message)
@app.route("/signup",methods=["post"])
def signup():
nickname=request.form["nickname"]
email=request.form["email"]
password=request.form["password"]
collection=db.user
result=collection.find_one({
"email":email
})
if result != None:
return redirect("/error?msg=信箱已被註冊")
collection.insert_one({"nickname":nickname,"email":email,"password":password
})
return redirect("/")
@app.route("/signin",methods=["post"])
def signin():
email=request.form["email"]
password=request.form["password"]
collection=db.user
result=collection.find_one({
"$and":[
{"email":email},
{"password":password}
]
})
if result==None:
return redirect("/error?msg=帳號或密碼錯誤")
session["nickname"]=result["nickname"]
return redirect("/member")
@app.route("/signout")
def signout():
del session["nickname"]
return redirect("/")
app.run(port=3000)
requirements.txt
Flask
pymongo[srv]
gunicorn
runtime.txt
python-3.10.2
出現的錯誤碼為
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/member-tian-wu.git'
之前上傳都正常
剛剛爬文看了一下是buildpack 不兼容
這個要怎麼解呢...
試著用github也一樣...
目前上傳成功了 https://git.heroku.com/member-tian-wu.git
但是變成 Method Not Allowed
但在本機跑 又正常...