Django的新手现在正在通过Rapidsms tutorial工作,并且在教程第2页遇到问题。
即使在对myhandlers.py进行编码并向settings.py添加必要的更改之后,消息测试程序也无法识别“帮助”命令。 myhandlers.py位于tut文件夹下。
ping-pong命令工作正常,因此消息测试工作正常。 这是相关的代码。
myhandlers.py
from rapidsms.contrib.handlers import KeywordHandler
help_text = {
'aaa': 'Help for aaa',
'bbb': 'Help for bbb',
'ccc': 'Help for ccc',
}
class HelpHandler(KeywordHandler):
keyword = "help"
def help(self):
"""Invoked if someone just sends `HELP`. We also call this
from `handle` if we don't recognize the arguments to HELP.
"""
self.respond("Allowed commands are AAA, BBB, and CCC. Send "
"HELP <command> for more help on a specific command.")
def handle(self, text):
"""Invoked if someone sends `HELP <any text>`"""
text = text.strip().lower()
if text == 'aaa':
self.respond(help_text['aaa'])
elif text == 'bbb':
self.respond(help_text['bbb'])
elif text == 'ccc':
self.respond(help_text['ccc'])
else:
self.help()
Now, add “rapidsms.contrib.handlers” to INSTALLED_APPS:
INSTALLED_APPS = [
...
"rapidsms.contrib.handlers",
...
]
and add your new class to RAPIDSMS_HANDLERS:
RAPIDSMS_HANDLERS = [
...
"myhandlers.HelpHandler",
...
]
答案 0 :(得分:2)
rapidsms_tut/rapidsms.log
文件,了解有关加载处理程序错误的详细信息。myhandlers.py
与manage.py位于同一目录中(或更改RAPIDSMS_HANDLERS
以指向rapidsms_tut.myhandlers
或您放置文件的位置。 答案 1 :(得分:1)
在设置文件中,它应该是
如下所列
RAPIDSMS_HANDLERS = [ ... &#34; the_application.myhandlers.HelpHandler&#34 ;, ... ]