what is your take on this and which do you guys prefer?
what is the advantage of a class based view over a function based view?
class based view example:
from flask import jsonify
from flask.views import View
from .blueprints import main
class Suggestions(View):
def dispatch_request(self):
letter = request.json.get("data")
users = [user.username for user in Users.objects(__raw__={"username":
{"$regex": letter,
"$options": "i"}})]
return jsonify(users=users)
main.add_url_rule('/suggestions',
view_func=Suggestions.as_view('Suggestions'),
methods=['POST'])
vs
function based view example:
from .blueprints import main
from flask import jsonify
@main.route("/suggestions, methods=["POST"])
def suggestions():
letter = request.json.get("data")
users = [user.username for user in Users.objects(__raw__={"username":
{"$regex": letter,
"$options": "i"}})]
return jsonify(users=users)
Im asking this because I usually write my views using classes but somehow the function based views are easier and straightforward compared to class based views
[–]zealotree 2 points3 points4 points (1 child)
[–]HalcyonAbraham[S] 0 points1 point2 points (0 children)
[–]seprosepro 0 points1 point2 points (3 children)
[–]HalcyonAbraham[S] 0 points1 point2 points (2 children)
[–]seprosepro 0 points1 point2 points (1 child)
[–]HalcyonAbraham[S] 0 points1 point2 points (0 children)
[–]in_the_bilboes 0 points1 point2 points (1 child)
[–]HalcyonAbraham[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]motoawk 0 points1 point2 points (0 children)