GAE工作,但在Spyder中导入webapp2失败



这是在html中测试重定向的简单代码。我用Spyder编写Python代码。

import webapp2
from valid_day import valid_day
from valid_month import valid_month
from valid_year import valid_year
from html_escape import escape_html
form = """
<form method="post">
    What is your birthday?
    <br>
    <label>
        Month
        <input type="text" name="month" value="%(month)s">
    </label>
    <label>
        Day
        <input type="text" name="day" value="%(day)s">
    </label>
    <label>
        Year
        <input type="text" name="year" value="%(year)s">
    </label>
    <div style="color: red">%(error)s</div>
    <br><br>
    <input type="submit">
</form>
"""
class MainPage(webapp2.RequestHandler):
    def write_form(self, error="", month="", day="", year=""):
        self.response.out.write(form %{"error": error,
                                       "month": escape_html(month),
                                       "day": escape_html(day),
                                       "year": escape_html(year)})
    def get(self):
        self.write_form()
    def post(self):
        user_month = self.request.get('month')
        user_day = self.request.get('day')
        user_year = self.request.get('year')
        month = valid_month(user_month)
        day = valid_day(user_day)
        year = valid_year(user_year)
        if not(month and day and year):
            self.write_form("That doesn't look valid to me, friend.", user_month, user_day, user_year)
        else:
            self.redirect("/thanks")
class ThanksHandler(webapp2.RequestHandler):
    def get(self):
        self.response.out.write("Thanks! That's a totally valid day!")
app = webapp2.WSGIApplication([('/', MainPage),
                              ('/thanks', ThanksHandler)],
                             debug=True)

虽然代码在GAE和我的http://localhost:8081/上工作得很好,但当我试图通过在Spyder中单击运行代码时失败了。错误信息是:没有名为webapp2的模块我也读过导入webapp2工作在谷歌应用程序引擎,即使我没有安装webapp2并将GAE目录添加到我的~/目录。Bashrc:

export PYTHONPATH="$PYTHONPATH:/home/lehr/Web/google_appengine/"
export PYTHONPATH="$PYTHONPATH:/home/lehr/Web/google_appengine/lib/"
export PYTHONPATH="$PYTHONPATH:/home/lehr/Web/google_appengine/lib/yaml"

GAE应用程序代码不打算直接执行,作为一个独立的应用程序,它需要由知道如何加载和执行应用程序代码的开发服务器执行(同时用模拟的GAE python沙盒功能补充它)。参见使用本地开发服务器。

可能能够执行它一起与SDK(即执行dev_appserver.py并传递它相同的参数,当你得到它的工作没有spyder)。但是我不熟悉Spyder,我不确定它是否支持通过第三方工具执行你的应用程序代码(如果它支持-如果它真的是实用/有用的开发)

最新更新