Prepare with our aggregated list of the most recurring viva questions. Click the answer button to reveal the full explanation.
8 questions
Can you explain what Flask is and why you chose it for your project?
Flask is a micro web framework for Python that is lightweight and easy to setup. I chose it because it is flexible, allows for quick development, and doesn't force a strict project structure.
What is the purpose of Flask(__name__)?
It helps Flask determine the root path of the application so it can accurately locate resources like templates and static files relative to the main script.
Why do we use if __name__ == "__main__" in Flask applications?
It ensures that the development server only runs if the script is executed directly as the main program, preventing the server from starting automatically if the file is imported elsewhere.
Can you explain how routing works in your Flask app?
Routing maps specific URLs to Python functions using the @app.route() decorator. When a user visits a URL, Flask executes the associated function and returns the result.
What does @app.route() do internally?
Internally, it registers a URL rule in the application's URL map, connecting the path string to the view function so the dispatcher knows what to call.
What is the difference between redirect() and url_for()?
redirect() sends the browser to a specific URL or path, while url_for() dynamically generates a URL for a specific function name, which is safer if paths change later.
Can a Flask route return different types of responses?
Yes, it can return HTML strings, rendered templates via render_template(), JSON data using jsonify(), or even custom Response objects with specific status codes.
How does data flow from frontend to backend in your application?
The frontend sends data via HTTP requests (like POST forms or AJAX). The backend captures this using request.form or request.json, processes it, and sends a response back.