Jan-11-2019, 07:48 PM
Do you have an ajax call, in javascript, that calls /view_count/recipie_id?
I'm just guessing, but it kinda looks like you never call the function that does the incrementing. But if you want it incremented every time the page is refreshed, why not just put the update in the controller?
ie, instead of:
I'm just guessing, but it kinda looks like you never call the function that does the incrementing. But if you want it incremented every time the page is refreshed, why not just put the update in the controller?
ie, instead of:
@app.route('/view_recipe/<recipe_id>') def view_recipe(recipe_id): the_recipe = mongo.db.recipes.find_one({"_id": ObjectId(recipe_id)}) return render_template('view_recipe.html', recipe=the_recipe) @app.route('/view_count/<recipe_id>') def view_count(recipe_id): mongo.db.recipes recipes.update({'_id': str(recipe_id)}, {'$inc': {'views': int(1)}}) return url_for('view_recipe.html')Why not just do:
@app.route('/view_recipe/<recipe_id>') def view_recipe(recipe_id): the_recipe = mongo.db.recipes.find_one({"_id": ObjectId(recipe_id)}) mongo.db.recipes.update({'_id': str(recipe_id)}, {'$inc': {'views': int(1)}}) return render_template('view_recipe.html', recipe=the_recipe)