How make simple static webapp through phython

To create a simple static web app using Python, you can use the Flask micro-framework. Flask allows you to serve static files like HTML, CSS, and JavaScript. Here’s a basic example:

  1. Install Flask: Make sure you have Flask installed. You can install it via pip:
   pip install Flask
  1. Create a folder for your project and navigate into it:
   mkdir my_static_app
   cd my_static_app
  1. Create a file named app.py:
   from flask import Flask, render_template

   app = Flask(__name__)

   @app.route('/')
   def index():
       return render_template('index.html')

   if __name__ == '__main__':
       app.run(debug=True)
  1. Create a folder named templates and place your HTML file (index.html) inside it:
   mkdir templates
   touch templates/index.html

Inside index.html, you can write your HTML code. Here’s an example:

   <!DOCTYPE html>
   <html lang="en">
   <head>
       <meta charset="UTF-8">
       <meta name="viewport" content="width=device-width, initial-scale=1.0">
       <title>My Static Web App</title>
       <link rel="stylesheet" href="static/style.css">
   </head>
   <body>
       <h1>Hello, World!</h1>
   </body>
   </html>
  1. Create a folder named static and place your CSS file (style.css) inside it:
   mkdir static
   touch static/style.css

Inside style.css, you can write your CSS code. Here’s an example:

   body {
       background-color: #f0f0f0;
       font-family: Arial, sans-serif;
       text-align: center;
   }

   h1 {
       color: #333;
   }
  1. Run your Flask application:
   python app.py
  1. Open your web browser and go to http://localhost:5000 to see your static web app in action.

This is a basic setup to get you started. You can expand upon it by adding more HTML, CSS, and JavaScript files as needed. Additionally, you can use Flask extensions like Flask-Assets to manage and bundle your static assets more efficiently.

Leave a Reply

Your email address will not be published. Required fields are marked *

nixede.com#interstitial