Jump to content

Flask/Dynamic Pages

From Wikiversity
(Redirected from Flask/Date and Time)

This lesson shows how to display dynamic content pages using Flask.

Readings

[edit | edit source]
  1. Wikipedia: Flask (web framework)

Multimedia

[edit | edit source]

Activities

[edit | edit source]
  1. Create or modify the Flask application page.
    • Modify main.py or app.py to include the following code:
      import flask

      app = flask.Flask(__name__)

      @app.route('/')
      def root():
          return str(datetime.datetime.now())

      if __name__ == "__main__":
          app.run(host='0.0.0.0', port=5000)
       
    • Run the program.
    • Refresh the output window or open a browser window to http://localhost:5000.
    • Refresh the output window again to see the dynamic content.
    • Stop the program.

References

[edit | edit source]