首页 > 解决方案 > 将 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 的菜鸟,我正在为课堂解决一个棘手的问题。有什么建议或解决方案吗?

标签: pythonhtmlfunctionreference

解决方案


推荐阅读