当前位置:首页 > 外汇 > 正文

世界杯竞猜源码

世界杯竞猜源码

后端(使用Python Flask)```pythonfrom flask import Flask, request, jsonifyfrom flask_sqlal...

后端(使用Python Flask)

```python

from flask import Flask, request, jsonify

from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///predictions.db'

db = SQLAlchemy(app)

class Prediction(db.Model):

id = db.Column(db.Integer, primary_key=True)

user_id = db.Column(db.Integer, nullable=False)

match_id = db.Column(db.Integer, nullable=False)

prediction = db.Column(db.String(1), nullable=False) 1 for win, 2 for draw, 3 for lose

@app.route('/predict', methods=['POST'])

def predict():

data = request.get_json()

user_id = data['user_id']

match_id = data['match_id']

prediction = data['prediction']

new_prediction = Prediction(user_id=user_id, match_id=match_id, prediction=prediction)

db.session.add(new_prediction)

db.session.commit()

return jsonify({'message': 'Prediction added successfully'

最新文章

随机文章