问题描述
我正在尝试允许用户通过以下方式将图像上传到我的Firebase存储数据库:
import pyrebase
from flask import *
app = Flask(__name__)
config = {
#Hidden
}
firebase = pyrebase.initialize_app(config)
storage = firebase.storage()
auth = firebase.auth()
@app.route('/',methods=['GET','POST'])
#Login
def basic():
unsuccessful = 'Please check your credentials'
successful = 'Login successful'
if request.method == 'POST':
email = request.form['name']
password = request.form['pass']
try:
auth.sign_in_with_email_and_password(email,password)
return render_template('index.html',s=successful)
except:
return render_template('new.html',us=unsuccessful)
return render_template('new.html')
#Posting function
@app.route('/','POST'])
def newProduct():
if request.method == 'POST':
try:
path_on_cloud = "images/newproduct.jpg"
path_local=request.form['file']
storage.child(path_on_cloud).put(path_local)
return render_template("index.html")
except:
return render_template("index.html")
允许用户登录的基本功能可以正常工作。 但是,当尝试将图片上传到firebase存储数据库时,出现以下404错误: “未找到 在服务器上找不到请求的URL。如果您手动输入网址,请检查拼写,然后重试。”
我有两个html文件:new.html(其中包含登录名)和index.html(其后是上载图片的页面)。
我希望你们中的一员能看到我做错了什么或我错过了什么。 预先感谢!
解决方法
在您共享的代码中,两个页面都具有相同的@ app.route。每个人都应该有自己的@ app.route。
发布功能应为:
@app.route('/newProduct',methods=['GET','POST'])