Back to notes
Describe the basic file structure of a Flask web application.
Press to flip
A basic Flask web application includes: `app.py` for the main Python file, `templates/` folder for HTML templates, `static/` folder for static files like CSS, JavaScript, and images, and `requirements.txt` to specify third-party libraries.
What is the purpose of using AJAX in web applications?
AJAX is used to make asynchronous requests to the server, allowing parts of a web page to be updated without refreshing the entire page. This makes web applications more dynamic and responsive.
Describe the role of SQLite in creating a simple web store using Flask.
SQLite is used to store data such as the catalog of books in a simple web store. It provides a lightweight database solution that integrates easily with Flask for managing and querying data.
What function is used to dynamically generate HTML templates in Flask and how is it used?
`render_template` is used to dynamically generate HTML templates. It is used by importing it from Flask and passing the HTML file and any variables to be rendered in the template.
How is JSON used in web development, and what are its benefits?
JSON is a format for transmitting data between the server and client. Its benefits include being lightweight, easy to read and write, and language-independent, making it a standard choice for web APIs.
Explain the purpose and basic usage of the `@app.route` decorator in Flask.
The `@app.route` decorator in Flask is used to map URLs to specific functions. These functions are called view functions, which handle the logic for the specified routes.
What are the main limitations of serving static content using the previously discussed HTTP server?
The HTTP server is limited to static content and lacks interactivity, which is necessary for creating dynamic web experiences.
What is the significance of the `requirements.txt` file in a Flask web application?
The `requirements.txt` file lists the third-party libraries needed for the Flask application. It allows for easy installation of dependencies using tools like pip.
Describe the process of implementing a login feature in Flask.
Implementing a login feature in Flask involves using the `session` variable to store user data, defining routes for login and logout, and handling user input and authentication with form submissions.
Explain how Flask manages user sessions.
Flask uses cookies to store session IDs on the client side and the `session` object to manage user state on the server side. This allows the server to remember information about the user between requests.
What is Flask, and why is it preferred over other frameworks like Django for certain projects?
Flask is a microframework for building web applications in Python. It is preferred for its simplicity and lightweight nature, making it easier to set up and use compared to Django.
What are cookies in the context of web development, and how are they used?
Cookies are data sent by the server to the client and stored by the client's browser. They are used to maintain state between client and server, such as keeping users logged in by storing session information.
What is template inheritance in Flask, and why is it useful?
Template inheritance in Flask uses `extends` and `block` tags to create a base layout that can be reused across multiple templates. It is useful for avoiding code duplication and maintaining consistent layouts.
How can you create a shopping cart in a Flask web application?
To create a shopping cart in Flask, you can use sessions to store cart state, define routes for adding and removing items, and dynamically update the cart based on user actions.
How can you handle form data in Flask using GET and POST methods?
In Flask, form data can be handled using `request.args` for GET requests and `request.form` for POST requests. These methods allow the extraction of user input from forms.
Previous
Next