2

此代码工作正常,除了comment: 它没有插入到消息正文中。

<div class="modal" id="feedback">
    <form action="/feedback" method="POST">
        <div class="modal-body">
            <textarea class="input-xxlarge" name="comment" rows="3"></textarea>
        </div>
        <div class="modal-footer">
            <a class="btn" type="submit" href="/feedback">Send</a>
        </div>
    </form>
</div>
class SendFeedback(webapp2.RequestHandler):
def get(self):
    user = users.get_current_user()
    comment = self.request.get('comment')
    message = mail.EmailMessage()
    message.sender = user
    message.to = 'foo@bar.com'
    message.subject = "Feedback from %s" % user
    message.body = """
            Feedback:
            %s
            """ % comment
    message.send()
    self.redirect(self.request.headers['referer'])

取决于ENCTYPE="multipart/form-data"%s或什么?

4

1 回答 1

3

forms 方法是 POST,而您的 Handler 实现了 GET 方法。

编辑

更改def get(self)def post(self)

class SendFeedback(webapp2.RequestHandler):
    def post(self):
        ...

帖子数据是:

data    = self.request.POST
comment = data.get('comment')

编辑2

此代码有效:

form = """
<div class="modal fade" id="feedback">
    <form action="/feedback" method="POST">
        <div class="modal-header"><h3>Aiutaci a migliorare</h3></div>
        <div class="modal-body">
            <p>un piacere sapere cosa cambiereste di Metrico</p>
                <textarea class="input-xxlarge" name="comment" rows="3"></textarea>
        </div>
        <div class="modal-footer"><input class="btn btn-inverse" type="submit"/></div>
    </form>
</div>
"""

class FormTest(webapp2.RequestHandler):

    def get(self):
        self.response.out.write(form)

    def post(self):
        data = self.request.POST
        comment = data.get('comment')
        body = """
Feedback:
%s
""" % comment
        self.response.out.write(body)
于 2012-05-01T12:50:21.047 回答