【发布时间】:2022-01-17 03:49:40
【问题描述】:
我目前通过 Google Cloud 的 App Engine 有一个“工作”网络应用程序。 当我访问我的网络应用程序时,唯一显示的是“欢迎使用我的 Python 程序!”我的 index.html 文件中有。
我正在尝试显示打印一些关于时间的字符串的其余 Python 代码。 我的文件中的内容不起作用,我不确定我做错了什么。我已经尝试过使用 Python 代码,因为我认为这是问题所在。也许我没有在正确的地方调用函数?
就文件而言,这是我所拥有的:
requirements.txt
Flask==2.0.2
pytz==2020.1
gunicorn==19.3.0
app.yaml
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 3
handlers:
- url: /static
static_dir: static
- url: /.*
script: auto
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
main.py
import pytz
from datetime import datetime
from flask import Flask, render_template
app = Flask(__name__)
def all_about_time():
#Prints local date.
current_time = datetime.now()
local_date = datetime.strftime(current_time, '%b %d, %Y')
print('Today\'s date is: ' + str(local_date))
#Prints out the time on the east coast. Helps give context on market hours.
eastern_time = datetime.strftime(current_time.astimezone(pytz.timezone('US/Eastern')), '%I:%M %p')
print('Time on the East Coast is currently: ' + eastern_time)
#This logic block dictates whether the market is closed or open. So far does not account for holidays.
day_of_week = datetime.strftime(current_time.astimezone(pytz.timezone('US/Eastern')), '%A')
dt_east = int(datetime.strftime(current_time.astimezone(pytz.timezone('US/Eastern')), '%H%M'))
if 930 <= dt_east <= 1600 and (day_of_week != 'Saturday' and day_of_week != 'Sunday'):
print('The market is open!')
else:
print('The market is closed.')
@app.route("/")
def hello():
all_about_time()
return render_template('index.html')
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<script src="{{ url_for('static', filename='script.js') }}"></script>
<link type="text/css" rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MyPythonProgram</title>
</head>
<body>
<h1>Welcome to my Python Program!</h1>
</body>
</html>
【问题讨论】:
标签: python flask google-cloud-platform web-applications