Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Python for Google应用程序引擎:不允许使用405方法_Javascript_Python_Google App Engine - Fatal编程技术网

Javascript Python for Google应用程序引擎:不允许使用405方法

Javascript Python for Google应用程序引擎:不允许使用405方法,javascript,python,google-app-engine,Javascript,Python,Google App Engine,您好,在测试的GET和POST方法时,我一直在使用405方法不允许此资源使用方法POST。计划是让用户发布姓名和昵称,并使用ajax保存然后显示输入 import webapp2 from google.appengine.ext.webapp.util import run_wsgi_app from google.appengine.ext import db from google.appengine.ext.webapp import template mainPage = """

您好,在测试的GET和POST方法时,我一直在使用405方法不允许此资源使用方法POST。计划是让用户发布姓名和昵称,并使用ajax保存然后显示输入

import webapp2
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.ext.webapp import template

mainPage = """
   <html>
<head>
    <title>Pokemon List</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
    <script src="js.js"></script>

</head>


<body>

    <div data-role="header" data-theme="a">
        <h1>Pokemon App</h1>
 <div data-role="page" id="menu" class="info">
        <div data-role="header">
            <h3>Menu</h3>
            <a href="#" data-role="button" data-rel="back" id="backbutton" data-theme="c" data-icon="arrow-l">Back</a>
        </div>

        <div data-role="menuList">
            <ul id="actions2" data-role="listview" >

                <li><a href="#input" data-transition="none">Input Data</a></li>
                <li><a href="#data" data-transition="none">Check Data</a></li>

            </ul>
        </div>
    </div>

<div data-role="page" id="input" class="info">
    <div data-role="header" data-theme="a">
        <h1>Post data</h1>
        <a href="#input" data-role="button" data-rel="back"  id="backbutton2" data-theme="c" data-icon="arrow-l">Back</a>
    </div>
  <title>Name and Message</title>
</head>
<body>
    <h2>Input Name</h2>
        <form method='post'>
        <label for="name">Name</label>
        <input type='text' id="name" name="name" size="40" value="{{user}}"/><br/>
        <label for="nickname">Nickname</label>
        <textarea id="nickname" name="nickname" rows="6" cols="50"></textarea><br/>
        <input type="submit" value="Submit Button" />
    </form><br/>

    <table>
            {% for nickname in messages %}
                {{ nickname.asTableRow }}
            {% endfor %}
        </table>



    <div data-role="namelist" >
        <ul data-role="listview" data-split-icon="delete" data-split-theme="a" data-inset="true" class="list"  id="list">


        </ul>
    </div>

</div>
</div>
   </div>


        </body>
</html>

"""

class Message(db.Model):
    # This one has 3 properties...


    user = db.StringProperty()
    name = db.StringProperty()
    nickname = db.StringProperty()
    timestamp = db.DateTimeProperty(auto_now_add=True)


    def asString(self):
        return "%s user name: %s the nickname %s " %(self.user, self.name, self.nickname)

    def asJSONString(self):
        return '{"name": "%s", "nickname": "%s"}' % (self.user, self.name, self.nickname)


class MainPage(webapp2.RequestHandler):
    def get(self):
        usr = self.request.get('user')
        nme = self.request.get('name')
        nnme = self.request.get('nickname')
       # self.response.headers['Content-Type'] = 'text/html'
        self.response.out.write(mainPage)

        if len(usr) > 0 and len(nnme) > 0:
            newmsg = Message(user=usr,name=nme,nickname=nnme)
            newmsg.put()
        #else:
            #self.response.out.write('Error in input')

def getJSONMessages(callback):
        messages = db.GqlQuery("SELECT * FROM Message ORDER BY timestamp")
        strlist = ""
        for message in messages:
            if len(strlist)>0:
                strlist += ',' + message.asJSONString()
            else:
                strlist = message.asJSONString()
        if callback =='':
            return '[' + strlist + ']'
        else:
            return callback+ '([' + strlist +']);'

class JSONInterface(webapp2.RequestHandler):

    def post(self):
        usr =self.request.get('usr')
        nnme =self.request.get('nnme')

        callback = self.request.get('callback')
        if len(usr) > 0 and len(nnme) >0:
            newmsg = Message(name=usr, nickname=nnme)
            newmsg.put()
        if len(usr)>0:
            self.response.out.write(getJSONMessages(callback))
        else:
            self.response.out.write("something didnt work")

    def get(self):
        callback = self.request.get('callback')
        self.response.out.write(getJSONMessages(callback))


app= webapp2.WSGIApplication([('/', MainPage),
                                      ('/json', JSONInterface)], debug=True)



def main():
    run_wsgi_app(app)

if __name__ == "__main__":
    main()
该应用程序已成功部署到Google应用程序引擎。我已经检查了App Engine中的日志,但没有发现错误。有人能告诉我我的python代码是否有问题吗。我目前正在使用javascript处理一些JSON,为了让get、POST方法正常工作,是否需要这样做? 谢谢你的时间和帮助

更新


如果我将我的主页请求处理程序更改为post,我仍然会得到405方法错误。

在您的方法是post的表单中,但在MainHandler中,您的方法是get,可能这就是为什么您在您的方法是post的表单中看到405方法不允许的原因,但在MainHandler中,您的方法是get,也许这就是为什么您会看到405方法不被允许的原因

我试图更改表单以获得。这允许提交按钮使用没有错误,但当试图使用post所有与邮递员插件我仍然得到405错误。此应用程序的目的是使用“提交”按钮发布该表单。谢谢你的建议,我将进一步研究这个问题。我尝试更改表单以获得更多信息。这允许提交按钮使用没有错误,但当试图使用post所有与邮递员插件我仍然得到405错误。此应用程序的目的是使用“提交”按钮发布该表单。谢谢你的建议,我会进一步研究这个问题。