传递“警报”的404错误从python到html页面的句子,但传递一个词没有错误 [英] 404 error passing a "Alert" sentence from python to html page, but no error for passing just a word
问题描述
更新:我得到的错误消息是404 Resource not found。
Update: The error message I get with the sentence is 404 Resource not found.
"GET /unexpected/The%20Notebook%20name%20is%20taken%20already HTTP/1.1" 404 -
当发生错误时,URL看起来像这样。
The URL looks like this when that error occurs.
http://localhost:8088/unexpected/The%20Notebook%20name%20is%20taken%20already
我试图在我的
应用程序中为用户错误创建一种Alert系统。在我看来,单词之间的空间是问题。但是必须有一个简单,优雅的方式来做到这一点。
I am attempting very poorly to create a sort of "Alert" system for user errors in my application. It appears to me that spaces between words are the problem. But there must be a simple, elegant way to do this.
在下面两行中,最上面一行有效,但不是最下面一行。 b
$ b
Of the two lines below, the top one works, but not the bottom one.
return webapp2.redirect("/unexpected/%s" % 'Hello')
# return webapp2.redirect("/unexpected/%s" % 'The Notebook name is taken already')
相应的定义如下。在这里,我希望评论的
out行可以工作,但也不会。
The corresponding definition is as follows. Here I would have preferred that the commented out line would work, but it will not, either.
class Unexpected(BaseHandler):
def get(self, reason):
template_values = {'reason':reason}
path = os.path.join(TEMPLATE_DIR, 'unexpected.html')
self.response.out.write(template.render(path, template_values))
# return webapp2.redirect('/unexpected/%s/ % reason')
app = webapp2.WSGIApplication([
('/', MainPage),
('/unexpected/([\w]+)', Unexpected)])
我如何获得发送到 unexpected.html
页面的消息?
How can I get a message sent to the unexpected.html
page? I have done this before with javascript Alerts, but am trying NOT to use javascript here.
{% extends "base.html" %}
{% block content %}
This unexpected result occurred: {{ reason }}
<br >
Click the back button and edit your entry.
{% endblock content %}
推荐答案
我的问题是,我试图在 def get(
>中没有数据存储模型来将信息传输到 def get(
。我定义了一个
def get(
,它使用一个名为 Trans
的数据存储模型来存储这样的事务包含在我的句子中的变量名为 reason
。
My problem is that I am trying to do this in def get(
without a datastore model to transfer information to the def get(
. I have defined a def get(
that uses a datastore model named Trans
that stores such transactional information that is contained in my sentence in a variable named reason
.
class Trans(db.Model):
reason = db.StringProperty()
我的模型命名为 Unexpected
如下所示。
My model named Unexpected
looks like the following.
class Unexpected(BaseHandler):
def get(self):
trans=Trans.get_by_key_name('reason')
template_values = {'trans':trans}
path = os.path.join(TEMPLATE_DIR, 'unexpected.html')
self.response.out.write(template.render(path, template_values))
我的python代码如下。
And my python codes is as follows.
reason='That Notebook name is taken already.'
trans = Trans(key_name='reason')
trans.reason=reason
trans.put()
template_values = {'trans':trans}
path = os.path.join(TEMPLATE_DIR, 'unexpected.html')
self.response.out.write(template.render(path, template_values))
我的 unexpected.html
代码如下。
{% extends "base.html" %}
{% block content %}
This unexpected result occurred: <emph style="font-weight: bold">{{ trans.reason }}</emph>
<br /><br />
<label>Click the "Ok" button and to go back to the previous page so you can edit your entry .
</label>
<form action="" method="post">
<input type="hidden" name="reason" value=""></input><br />
<input type="submit" value="Ok"/>
</form>
{% endblock content %}
这篇关于传递“警报”的404错误从python到html页面的句子,但传递一个词没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!