404传递一个“错误”;“警惕”;从python到html页面的语句,但只传递一个单词没有错误
更新:我收到的句子错误消息是404资源未找到404传递一个“错误”;“警惕”;从python到html页面的语句,但只传递一个单词没有错误,html,python-2.7,alert,Html,Python 2.7,Alert,更新:我收到的句子错误消息是404资源未找到 "GET /unexpected/The%20Notebook%20name%20is%20taken%20already HTTP/1.1" 404 - 发生该错误时,URL如下所示 http://localhost:8088/unexpected/The%20Notebook%20name%20is%20taken%20already 我试图为我的系统中的用户错误创建一种“警报”系统,但效果很差 应用在我看来,单词之间的空格是个问题。但必须有
"GET /unexpected/The%20Notebook%20name%20is%20taken%20already HTTP/1.1" 404 -
发生该错误时,URL如下所示
http://localhost:8088/unexpected/The%20Notebook%20name%20is%20taken%20already
我试图为我的系统中的用户错误创建一种“警报”系统,但效果很差
应用在我看来,单词之间的空格是个问题。但必须有一个简单、优雅的方法来做到这一点
在下面的两行中,最上面的行起作用,但最下面的行不行
return webapp2.redirect("/unexpected/%s" % 'Hello')
# return webapp2.redirect("/unexpected/%s" % 'The Notebook name is taken already')
相应的定义如下。在这里,我更希望
外线可以工作,但也不行
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
页面的消息?我以前用javascript警报做过这件事,但我尝试在这里不使用javascript
{% extends "base.html" %}
{% block content %}
This unexpected result occurred: {{ reason }}
<br >
Click the back button and edit your entry.
{% endblock content %}
{%extends“base.html”%}
{%block content%}
出现此意外结果:{reason}
单击“上一步”按钮并编辑您的条目。
{%endblock内容%}
我的问题是,我试图在def get(
中执行此操作,但没有数据存储模型将信息传输到def get(
)。我已定义了def get(
使用名为Trans
的数据存储模型,该模型将包含在我的语句中的此类事务信息存储在名为reason
的变量中
class Trans(db.Model):
reason = db.StringProperty()
我的名为意外的
的模型如下所示
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代码如下所示
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 %}
{%extends“base.html”%}
{%block content%}
出现此意外结果:{trans.reason}
单击“确定”按钮并返回上一页,以便您可以编辑条目。
{%endblock内容%}
这实际上是对您的问题的解决方案吗?如果是,您应该接受它。如果不是,这属于对原始问题的编辑。