You can divide your HTML, CSS, and JavaScript code into separate files and link to them from an HTML file. This can make your code easier to organize and maintain.

To link to a CSS file from an HTML file, you can use a link element in the head section of the HTML file, like this:

<link rel="stylesheet" type="text/css" href="style.css">

To link to a JavaScript file from an HTML file, you can use a script element in the head or body section of the HTML file, like this:

<script type="text/javascript" src="script.js"></script>

Here is an example of an HTML file that links to a CSS file and a JavaScript file:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
  <button class="tile-button" onclick="displayDate()">Click me</button>

  <script type="text/javascript" src="script.js"></script>
</body>
</html>

Flask is a popular Python web framework that allows you to build web applications quickly. To use Flask to serve your static HTML site, you will need to create a Python script that runs a Flask web server.

Here is an example of a Python script that runs a Flask web server and serves the files in a directory called static:

from flask import Flask, send_from_directory

app = Flask(__name__)

@app.route('/<path:path>')
def serve_static(path):
    return send_from_directory('static', path)

if __name__ == '__main__':
    app.run()

To run the server, you can use the following command:

$ python server.py

The server will be available at http://localhost:5000. You can put your HTML, CSS, and JavaScript files in the static directory, and they will be served by the Flask web server.

Here is an example of the folder structure you could use to serve a static HTML site using Flask:

.
├── server.py
└── static
    ├── index.html
    ├── style.css
    └── script.js
  • server.py is the Python script that runs the Flask web server.
  • static is the directory that contains your HTML, CSS, and JavaScript files.

You can put all of your static assets (e.g., images, fonts) in the static directory as well.

To run the server, you can use the following command:

$ python server.py

The server will be available at http://localhost:5000. You can access your HTML files by visiting http://localhost:5000/index.html, for example.


Posted

in

,

by

Comments

Leave a Reply

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