我有网址和相应的视图如下。
url(r'^(?P<token>.*?)/ack$', views.api_ACK, name='device-api_ack')
def api_ACK(request, token):
"""
Process the ACK request comming from the device
"""
logger.info('-> api_ACK', extra={'request': request, 'token' : token, 'url': request.get_full_path()})
logger.debug(request)
if request.method == 'GET':
# verify the request
action, err_msg = api_verify_request(token=token, action_code=Action.AC_ACKNOWLEDGE)
return api_send_answer(action, err_msg)
我想从另一个视图api_send_answer
以请求方法调用api_ACK
函数作为GET
我正在/device/LEAB86JFOZ6R7W4F69CBIMVBYB9SFZVC/ack
视图中api_send_answer
创建一个网址,如下所示。
def api_send_answer(action, err_msg, provisional_answer=None):
last_action = create_action(session,action=Action.AC_ACKNOWLEDGE,token=last_action.next_token,timer=500)
url = ''.join (['/device/',last_action.next_token ,'/',Action.AC_ACKNOWLEDGE])
logger.debug('Request Url')
logger.debug(url)
response = api_ACK(request=url,token=last_action.next_token) # This is wrong
现在从api_send_answer
开始重定向到api_ACK
视图,但如何使用请求方法调用api_ACK
作为GET?
请帮助..任何建议对我有帮助
答案 0 :(得分:0)
这一行
response = api_ACK(request=url,token=last_action.next_token)
是错误的,因为视图需要HttpRequest
个对象而你会给他提供网址。
如果您需要向用户返回查看响应,可以使用重定向:
def api_send_answer(action, err_msg, provisional_answer=None):
last_action = create_action(session,action=Action.AC_ACKNOWLEDGE,token=last_action.next_token,timer=500)
url = ''.join (['/device/',last_action.next_token ,'/',Action.AC_ACKNOWLEDGE])
logger.debug('Request Url')
logger.debug(url)
return HttpResponseRedirect(url)
如果您需要对视图响应执行其他操作,则必须使用HttpRequest
object而不是url作为参数。