Create Random Quote Generation webapp in python

 Creating a simple quote generation web application in Python can be an interesting project. This app would generate and display random quotes to users. Here's a step-by-step guide on how to build it:


**Step 1: Set Up Your Development Environment**


Ensure you have Python installed on your system. You may also want to use a Python web framework. For this example, we'll use Flask, a lightweight web framework.


```bash

pip install flask

```


**Step 2: Create the Project Structure**


Organize your project files and directories. A simple structure might include:


```

quote_app/

|-- app.py

|-- templates/

| |-- index.html

|-- static/

| |-- style.css

```


**Step 3: Write the Flask Application**


In `app.py`, create a basic Flask application:


```python

from flask import Flask, render_template

import random


app = Flask(__name__)


# List of quotes (you can expand this list)

quotes = [

    "The only way to do great work is to love what you do. - Steve Jobs",

    "Innovation distinguishes between a leader and a follower. - Steve Jobs",

    "Simplicity is the ultimate sophistication. - Leonardo da Vinci",

    "The journey of a thousand miles begins with one step. - Lao Tzu",

]


@app.route("/")

def index():

    # Generate a random quote

    random_quote = random.choice(quotes)

    return render_template("index.html", quote=random_quote)


if __name__ == "__main__":

    app.run(debug=True)

```


**Step 4: Create HTML Template**


In `templates/index.html`, create the HTML template to display the random quote:


```html

<!DOCTYPE html>

<html>

<head>

    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">

</head>

<body>

    <div class="quote-container">

        <h1>Random Quote</h1>

        <blockquote>{{ quote }}</blockquote>

    </div>

</body>

</html>

```


**Step 5: Add CSS Styles**


In the `static` directory, create a CSS file (`style.css`) to style your web page. You can customize this according to your preferences.


**Step 6: Run the Application**


Run your Flask application:


```bash

python app.py

```


Visit `http://localhost:5000` in your web browser to see your quote generation web app in action.


**Step 7: Expand the Quote List**


You can expand the list of quotes in the `quotes` list to provide a more diverse set of quotes to your users.


This is a simple example of a quote generation web app. You can further enhance it by allowing users to request new quotes, adding a database to store quotes, or integrating an API for quote retrieval.

Comments

Popular posts from this blog

bad character U+002D '-' in my helm template

GitLab pipeline stopped working with invalid yaml error

How do I add a printer in OpenSUSE which is being shared by a CUPS print server?