Flask

flask sqlalchemy many to many relationship with extra field

谁说胖子不能爱 提交于 2020-12-29 09:06:31
问题 I have 2 tables: restaurants and foods, and a 3rd table restaurants_foods which stores the many to many relationship between the 2 tables restaurants_foods = db.Table('restaurants_foods', db.Column('restaurant_id', db.Integer, db.ForeignKey('restaurants.id'), primary_key=True), db.Column('food_id', db.Integer, db.ForeignKey('foods.id'), primary_key=True), db.Column('food_price', db.Float) ) class Food(Model): __tablename__ = "foods" id = db.Column(db.Integer, primary_key=True, autoincrement

flask sqlalchemy many to many relationship with extra field

天大地大妈咪最大 提交于 2020-12-29 09:06:20
问题 I have 2 tables: restaurants and foods, and a 3rd table restaurants_foods which stores the many to many relationship between the 2 tables restaurants_foods = db.Table('restaurants_foods', db.Column('restaurant_id', db.Integer, db.ForeignKey('restaurants.id'), primary_key=True), db.Column('food_id', db.Integer, db.ForeignKey('foods.id'), primary_key=True), db.Column('food_price', db.Float) ) class Food(Model): __tablename__ = "foods" id = db.Column(db.Integer, primary_key=True, autoincrement

Use Flask SocketIO to update webpage everytime a local file changes

流过昼夜 提交于 2020-12-29 08:15:44
问题 I need to update my webpage every time my local file:filename is changed. Without the use of sockets, I can simply refresh the page every 1 second and get it done. I was doing this by reading the contents of filename and sending it to my web template. But I need to use sockets and make this process asynchronous so that auto refresh is not used. I'm using Flask as my web framework. 回答1: Below is an example Flask application which watches a file and emits a socket message whenever the file is

Use Flask SocketIO to update webpage everytime a local file changes

无人久伴 提交于 2020-12-29 08:08:01
问题 I need to update my webpage every time my local file:filename is changed. Without the use of sockets, I can simply refresh the page every 1 second and get it done. I was doing this by reading the contents of filename and sending it to my web template. But I need to use sockets and make this process asynchronous so that auto refresh is not used. I'm using Flask as my web framework. 回答1: Below is an example Flask application which watches a file and emits a socket message whenever the file is

How can I unit test this Flask app?

孤街浪徒 提交于 2020-12-29 06:55:28
问题 I have a Flask app that is using Flask-Restless to serve an API. I have just written some authentication that checks If the consumers host is recognised The request includes a hash (calculated by encrypting the request content for POST and URL for GET along with a secret API key) and The hash is valid I want to be able to write some unit tests for this, but I'm not sure how because my functions use the request object. Should I be mocking the request object? Would love some advice on this.

How can I get current base URI in flask? [duplicate]

烂漫一生 提交于 2020-12-29 06:11:37
问题 This question already has answers here : How do I get the different parts of a Flask request's url? (4 answers) Closed 3 years ago . In below code, i want to store URL in a variable to check error on which URL error occured. @app.route('/flights', methods=['GET']) def get_flight(): flight_data= mongo.db.flight_details info = [] for index in flight_data.find(): info.append({'flight_name': index['flight_name'], 'flight_no': index['flight_no'], 'total_seat': index['total_seat'] }) if request

How can I get current base URI in flask? [duplicate]

会有一股神秘感。 提交于 2020-12-29 06:07:52
问题 This question already has answers here : How do I get the different parts of a Flask request's url? (4 answers) Closed 3 years ago . In below code, i want to store URL in a variable to check error on which URL error occured. @app.route('/flights', methods=['GET']) def get_flight(): flight_data= mongo.db.flight_details info = [] for index in flight_data.find(): info.append({'flight_name': index['flight_name'], 'flight_no': index['flight_no'], 'total_seat': index['total_seat'] }) if request

Flask restful pagination

妖精的绣舞 提交于 2020-12-28 20:54:24
问题 I need to throw together an very simple API with a short deadline. Flask-restful seems ideal except for one thing: I can't find anything in the documentation about pagination. Given a simple endpoint like this: from flask import Flask, request from flask_restful import Resource, Api from sqlalchemy import create_engine import json app = Flask(__name__) api = Api(app) class Employees(Resource): def get(self): return json.dumps([{'employees': 'hello world'} for i in range(1000)]) api.add

flask - something more strict than @api.expect for input data?

a 夏天 提交于 2020-12-28 07:51:07
问题 In my flask-restplus API I'd like not only to check that input data, like in the following example resource_fields = api.model('Resource', { 'name': fields.String(default = 'string: name', required = True), 'state': fields.String(default = 'string: state'), }) @api.route('/my-resource/<id>') class MyResource(Resource): @api.expect(resource_fields, validate=True) def post(self): ... must have 'name' field and may have 'state' field, but also to check that there are no other fields (and to

flask - something more strict than @api.expect for input data?

两盒软妹~` 提交于 2020-12-28 07:50:53
问题 In my flask-restplus API I'd like not only to check that input data, like in the following example resource_fields = api.model('Resource', { 'name': fields.String(default = 'string: name', required = True), 'state': fields.String(default = 'string: state'), }) @api.route('/my-resource/<id>') class MyResource(Resource): @api.expect(resource_fields, validate=True) def post(self): ... must have 'name' field and may have 'state' field, but also to check that there are no other fields (and to