python - 将 HTML 按钮引用到 Python 脚本
问题描述
我在这个程序中的目标是将信息存储在数据库中。我的问题是我正在尝试使用 Python 脚本从我的 HTML 页面链接一个按钮。我的导师告诉我们,它必须用 Python 编写。任何支持 Python 2.7 的库都适合我。
from google.appengine.api import images
from google.appengine.ext import ndb
from models import Note
import webapp2
import jinja2
import os
jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)))
class MainHandler(webapp2.RequestHandler):
def get(self):
template = jinja_env.get_template('./main.html')
self.response.out.write(template.render())
class InfoHandler(webapp2.RequestHandler):
def get(self):
note = Note(img = images.Image(photo.usr_img))
class Note(ndb.Model):
def get(self):
usr_img = ndb.BlobProperty()
desc = ndb.StringProperty()
app = webapp2.WSGIApplication([
('/', MainHandler),
], debug=True)
<html>
<head lang = "en">
<meta charset = "UTF-8">
<title>Title</title>
</head>
<body>
<div class = "container">
<h1>If this is an emergency, upload a photo and provide a short description.</h1>
<div id = "upload" >
<label for = "img">Upload image:</label>
<input type = "file" name = "pic" accept = "image/*"/>
<label for = "desc">Description:</label>
<input type = "text" />
<input type = "submit" href = "{{ submit_data }}"/>
</div>
</div>
</body>
</html>
我是 Python 的菜鸟,我正在为课堂解决一个棘手的问题。有什么建议或解决方案吗?
解决方案
推荐阅读
- amazon-iam - 调用 PutRolePolicy 操作时发生错误(ValidationError):policyDocument 的指定值无效
- ios - 为什么我不能更改 Timer.scheduledTimer 函数中变量的值?
- javascript - 循环删除和添加对象属性
- image - Android Studio - 将位图保存到图库不正确
- r - 如何通过分组合并行并仅在R中保留最高值
- cordova - 从 Cordova android 模拟器打印
- powershell - 需要使用 Powershell 向 Teams 发送 .csv
- ios - Swift 中的递归函数在使用大量输入调用时崩溃
- python - pandas 中的列表列(如果存在于另一个列表中)
- javascript - 谷歌脚本:设置自定义比例,导出为 PDF 时