我仍然遇到webapp2的错误,我在这里可能会遇到什么问题.
ERROR 2011-12-13 11:17:19,059 webapp2.py:1528] 'NoneType' object has no attribute 'route'
Traceback (most recent call last):
File "/home/user/sdk/google_appengine/lib/webapp2/webapp2.py", line 1511, in __call__
rv = self.handle_exception(request, response, e)
File "/home/user/sdk/google_appengine/lib/webapp2/webapp2.py", line 1505, in __call__
rv = self.router.dispatch(request, response)
File "/home/user/sdk/google_appengine/lib/webapp2/webapp2.py", line 1253, in default_dispatcher
return route.handler_adapter(request, response)
File "/home/user/sdk/google_appengine/lib/webapp2/webapp2.py", line 1077, in __call__
return handler.dispatch()
File "/home/user/sdk/google_appengine/lib/webapp2/webapp2.py", line 526, in dispatch
method_name = request.route.handler_method
AttributeError: 'NoneType' object has no attribute 'route'
ERROR 2011-12-13 11:17:19,060 wsgi.py:186]
Traceback (most recent call last):
File …Run Code Online (Sandbox Code Playgroud) 我想在Python 2.5下使用webapp2,这是Python 2.7的默认设置.这可能吗?怎么样?
我有一个python字典,我试图通过pickle属性存储在GAE Gql数据存储区中.
我试着按照这个问题回答, 在GAE中存储一个词典列表
但它不适用于我的代码下面..我得到一个错误,我的列表有问题
我设置了pickle属性和数据模型类,如下所示,
class PickleProperty(db.Property):
def get_value_for_datastore(self, model_instance):
value = getattr(model_instance, self.name, None)
return pickle.dumps(value)
def make_value_from_datastore(self, value):
return pickle.mloads(value)
class MDB(db.Model):
Name = db.StringProperty(required=True)
Times = PickleProperty()
created = db.DateTimeProperty(auto_now_add = True)
Run Code Online (Sandbox Code Playgroud)
我的代码中有一个函数,它插入数据并将其读出
def m_time_manage(m=""):
if not m:
r = db.GqlQuery("select * from MDB")
else:
#find specific masjid requested
r = db.GqlQuery("select * from MDB where Name = %s" % (s))
#if masjid time data doesn't exist in db throw in placeholders...
if r is None: …Run Code Online (Sandbox Code Playgroud) 使用DB,我想创建一个非常大的字典.如果我将它保存到磁盘,当腌制时,它需要大约10 MB的空间.
我想做的是:
将此字典保存到磁盘,以打开该文本文档并将其复制到另一个py文件,以便每次每次通过Web应用程序调用py文档时都不必重新生成它,它是可迭代的.
我怎样才能做到这一点?
PS.我的应用程序正在Google应用引擎上运行,我想解决这个问题,以避免使用DB等资源.
我有一个带有一些阿拉伯数字的网页,其中有一个音频播放鼠标悬停动作,数字变得明显.它在我的浏览器中本地工作,但它不适用于谷歌应用程序引擎.它也无法在谷歌应用引擎下本地工作,但如果我只是运行html文件,它的工作原理.这是我的代码的一部分
<script language="javascript" type="text/javascript">
function playSound(soundfile) {
document.getElementById("dummy").innerHTML=
"<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
};
</script>
Run Code Online (Sandbox Code Playgroud)
<div>
<table>
<tr>
<td onmouseover="playSound('numbers/1.mp3');">?????</td>
<td onmouseover="playSound('numbers/1st.mp3');">????????</td>
<td onmouseover="playSound('numbers/1st_f.mp3');">???????</td>
<td onmouseover="playSound('numbers/saturday.mp3');">????????</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
这是python代码
import os
import webapp2
import jinja2
from google.appengine.ext import db
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
autoescape=True)
class Handler(webapp2.RequestHandler):
def write(self, *a, **kw):
self.response.out.write(*a, **kw)
def render_str(self, template, **params):
t = jinja_env.get_template(template)
return t.render(params)
def render(self, template, **kw):
self.write(self.render_str(template, **kw))
class MainPage(Handler):
def get(self):
self.render('ArabicNumbers.html')
app = …Run Code Online (Sandbox Code Playgroud) 有没有办法找出webhandler的当前URL是否包含#?当我使用#时,我无法写出URL.
self.request.url当带有#的URL在服务器上为GET时,仅返回基本URL.
我还尝试将其余的URL作为参数发送并打印出来.
('/(.*)', MainHandler),
class MainHandler(webapp2.RequestHandler):
def get(self, args):
self.response.out.write(args)
Run Code Online (Sandbox Code Playgroud)
当URL与URL中的#一起使用时,这不会在args参数上发布任何内容.对于其他所有内容,它会在基础之后成功写入其余的URL.我正在尝试显示哪种URL的示例:http://instahashtag.appspot.com/#/14212311
我错过了什么吗?
我有一个简单的wiki网络应用程序.它允许登录的用户编辑现有主题,或者如果该主题没有页面,则创建新内容.我一直在努力创建一个版本历史页面,列出主题的最后n次编辑以及日期/编辑器.但是,我终于成功地在一个主题的历史页面上显示了n个先前版本的列表.我的问题并不正是为什么我现在正在做的事情......但为什么我之前尝试过的事情不起作用.
这是"历史"页面的处理程序类.它的get方法接收主题为以下形式的arg '/topic':
class History(Main):
""" Display previous versions of a topic if they exist """
def get(self, topic):
topic = topic[1:]
history = Version.get_topic_history(topic).fetch(10)
if history:
self.render('history.html', history=history, topic=topic)
else:
self.redirect('/%s' % topic)
Run Code Online (Sandbox Code Playgroud)
以下是存储所有主题编辑的模型.它有一个classmethod,get_topic_history.它按主题名称查询所有实体的Version类,然后按创建日期返回它们.这有效.但是,你可以看到就在那条线上方,注释掉了,就是我原来做的,那是行不通的.在第一个注释掉的行中,我检索了具有包含特定主题名称的祖先路径的所有实体的密钥(我认为这称为祖先查询,至少,这是我理解它要做的事情).然后我通过祖先路径返回一个查询,并按创建日期/时间排序.您可以从History处理程序中调用此方法.对我来说,看起来应该返回与我当前方法相同的结果,但它什么也没有返回.谁能告诉我为什么?并提前感谢所有答案.
class Version(ndb.Model):
""" wiki version history """
created = ndb.DateTimeProperty(auto_now_add=True)
author = ndb.StringProperty(required=True)
topic = ndb.StringProperty(required=True)
content = ndb.TextProperty(required=True)
@classmethod
def get_topic_history(cls, topic):
# key = ndb.Key(cls, topic, parent=version_key())
# return cls.query(ancestor=key).order(-cls.created)
return cls.query(cls.topic == topic).order(-cls.created)
Run Code Online (Sandbox Code Playgroud)
这是我存储版本的方式:
version = Version(topic=topic, …Run Code Online (Sandbox Code Playgroud) python google-app-engine jinja2 webapp2 google-cloud-datastore
我有一个建立在gae上的应用程序.我使用python和webapp2框架.我需要将301重定向从www.my-crazy-domain.com重定向到my-crazy.domain.com,以便在搜索结果中消除www和not-www双打.
有没有人有现成的解决方案?谢谢你的帮助!
我在GAE上有一个应用程序,用于检查管理员是否在调用任何网页之前登录.我已经尝试了各种方法来管理登录过程.
Q1 - 我在第二个例子中的装饰师做错了什么?
Q2 - 人们通常也会对帖子功能进行检查吗?
之前我在每个get函数中使用了if语句.问题是我会在每个函数中反复重复这个if语句.
class IncomePage(webapp2.RequestHandler):
def get(self):
if users.is_current_user_admin():
self.response.write('My Webpage')
else:
self.response.write('Please Login')
Run Code Online (Sandbox Code Playgroud)
然后我试着让装饰师为我做这件事.它没有用,所以我做错了什么.
def check(func):
if users.is_current_user_admin():
return func
else:
response.write('Please Login') ### Doesn't work
class IncomePage(webapp2.RequestHandler):
@check
def get(self):
self.response.write('My Webpage')
Run Code Online (Sandbox Code Playgroud) 在我的RequestHandler子类中,我试图获取URL的范围:
class GetStats(webapp2.RequestHandler):
def post(self):
lastpage = 50
for page in range(1, lastpage):
tmpurl = url + str(page)
response = urllib2.urlopen(tmpurl, timeout=5)
html = response.read()
# some parsing html
heap.append(result_of_parsing)
self.response.write(heap)
Run Code Online (Sandbox Code Playgroud)
但它适用于~30个网址(页面加载时间很长但是有效).如果超过30,我收到错误:
错误:服务器错误
服务器遇到错误,无法完成您的请求.
请在30秒后再试一次.
有什么方法可以获取很多网址吗?可能更优或更好?最多几百页?
更新:
我使用BeautifulSoup来解析每一页.我在gae日志中找到了这个追溯:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 267, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch() …Run Code Online (Sandbox Code Playgroud) 我正在使用Flask,Jinja2模板(html文件)发布存储在ABC.py结果中的熊猫数据框表。表格看起来像:图片
我正在使用字典进行打印,但是格式不正确
<div class="col-sm-5 col-sm-offset-1">
{% if results is not none %}
<h2>Compare</h2>
<br>
<div id="results">
<table class="table table-striped" style="max-width: 300px;">
<thead>
<tr>
<th>Specifications</th>
<th>part1</th>
<th>part2</th>
</tr>
</thead>
{% for key,value in results.iterrows() %}
<tr> <option value = {{value[0]}} </option> </tr>
<tr>
<option value = "{{value[0]}}">{{value[1]}}</option>
</tr>
# <option value="{{ value['0']}}">{{value['1'] }}</option>
{% endfor %}
</table>
</div>
{% endif %}
</div>Run Code Online (Sandbox Code Playgroud)
必须使用jinja2模板来做其他事情,但要停留在最底层。有任何建议请。
谢谢
我一直在尝试获取请求URL如下
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
print self.request.get('url')
app = webapp2.WSGIApplication([('/.*', MainPage)], debug=True)
Run Code Online (Sandbox Code Playgroud)
当请求是
http://localhost:8080/index.html
Run Code Online (Sandbox Code Playgroud)
它给了我类似的东西
Status: 200 Content-Type: text/html; charset=utf-8 Cache-Control: no-cache Content-Length: 70
Run Code Online (Sandbox Code Playgroud)
我需要得到的是类似的东西
index.html
Run Code Online (Sandbox Code Playgroud)
编辑:这样我就可以检查字符串并相应地显示正确的html /模板文件.
我已经检查过Request文档并尝试了很多替代方案但我似乎无法找到解决方案.我对网络开发很陌生.我错过了什么?