如何將某些資料傳送到Python和Google地圖引擎中的Thread模組

2024-05-08 13:45:02 发布

您现在位置:Python中文网/ 问答频道 /正文

from google.appengine.ext import db
class Log(db.Model):
    content = db.StringProperty(multiline=True)

class MyThread(threading.Thread):
    def run(self,request):
        #logs_query = Log.all().order('-date')
        #logs = logs_query.fetch(3)
        log=Log()
        log.content=request.POST.get('content',None)
        log.put()

def Log(request):
    thr = MyThread()
    thr.start(request)
    return HttpResponse('')

错误是:

TypeError at /log
start() takes exactly 1 argument (2 given)

当我不发送请求时

class MyThread(threading.Thread):
    def run(self):
        log=Log()
        log.content=request.POST.get('content',None)
        log.put()
def Log(request):
    thr = MyThread()
    thr.start()

    return HttpResponse('')

错误是:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "D:\Python25\lib\threading.py", line 486, in __bootstrap_inner
    self.run()
  File "D:\zjm_code\helloworld\views.py", line 33, in run
    log.content=request.POST.get('content',None)
NameError: global name 'request' is not defined

Tags: runselflogdbrequestdefcontentpost
2条回答

你不能在应用程序引擎上使用线程。你知道吗

我不确定这将满足您的需要,甚至可能在谷歌appengine,但

如果将thr.start(request)更改为thr.run(request),则错误应该消失

相关问题 更多 >

    热门问题