3

the following is my code for get method:

def get(self, ques_no, i):
    j=i
    opt_dict = {}
    for ques in session.query(Options.optn).filter(Options.q_no == ques_no)[j:j+2]:
        opt_dict.update({i:ques.optn})
        i=i+1
    return jsonify(opt_dict)            

api.add_resource(store_option, '/option/&&', endpoint = 'option_id')

i need to pass to arguments to my get method to access the database. but i'm not able pass to arguments. how can i do that?? any help will be appreciated..

4
  • Are the arguments you need to pass specific to each request, fixed?
    – Ami Tavory
    Mar 2, 2016 at 5:25
  • But you are already passing arguments like ques_no and i, no? I don't understand your question, then.
    – Ami Tavory
    Mar 2, 2016 at 6:29
  • This way is not correct. These two parameters are to be received using http get request Mar 2, 2016 at 6:50
  • I'm getting error here.... Mar 2, 2016 at 6:50

1 Answer 1

3

From modifying my own code, something like this should work.

Start by defining a class like this:

class DBAccessor(Resource):                                                                                                                      
    def put(self, ques_no, i):      
        ...                             
        return 'ok'                             

Now connect it like this:

app = Flask('wasp')                                                          
api = Api(app)                                                                  

api.add_resource(                                                               
    DBAccessor,                                                
    '/option/<ques_no>/<i>')            
2
  • Type error: get() got an unexpected keyword argument 'q_no' Mar 2, 2016 at 8:35
  • IDK, it works for me. I suggest you create a MCVE showing the error you got.
    – Ami Tavory
    Mar 2, 2016 at 8:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.