如何定义响应?

2024-04-25 09:56:18 发布

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

我想修一个房间问题。比如这是:

from django.http import HttpResponse
import datetime
def current_datetime(request):
          now = datetime.datetime.now()
          if now == 2013:
                          html = "<html><body>It is now %s.</body></html>" % now
                          return HttpResponse(html)
          else:
                         # giva a response first 
                         urllib.urlopen(message)
                         # do something 
                         print 'not 2013'
                         sys.exit(0)

“如何使用”urllib.urlopen文件(message)”而不是“HttpResponse()”?
不要使用HttpResponse(),而是给出响应。 非常感谢。你知道吗


Tags: djangofromimporthttpmessagedatetimedefhtml
1条回答
网友
1楼 · 发布于 2024-04-25 09:56:18

根据我使用Django的经验,通过视图传递请求的每个函数最终都必须返回一个HttpRequest对象。为什么你需要在发送回复之后而不是之前做“某件事”?你知道吗

相关问题 更多 >