gpt4 book ai didi

django - “请求”对象没有属性 'META'

转载 作者:行者123 更新时间:2023-12-04 05:30:09 24 4
gpt4 key购买 nike

这是我的看法:

def data(request, symbol):
context_dict = {}

NASDAQ = "http://www.nasdaq.com/symbol/{}/financials?query=income-statement".format(symbol)

import urllib.request
from bs4 import BeautifulSoup

user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'
headers = {'User-Agent': user_agent, }
request = urllib.request.Request(NASDAQ, None, headers) # The assembled request
response = urllib.request.urlopen(request)
html_data = response.read() # The data u need

soup = BeautifulSoup(html_data)
genTable = soup.find_all("div", class_="genTable")

context_dict['genTable'] = genTable

return render(request, 'data.html', context_dict)

当我返回 HttpResponse时,没有错误。

我正在尝试将上面的context_dict渲染到数据模板中。这给了我 'Request' object has no attribute Meta。我该如何解决?

最佳答案

您用该行中的局部变量替换了传递给 View 的请求对象

request = urllib.request.Request(NASDAQ, None, headers)  # The assembled request

将此变量命名为其他名称。喜欢
assembled_request = urllib.request.Request(NASDAQ, None, headers)  # The assembled request
response = urllib.request.urlopen(assembled_request)

关于django - “请求”对象没有属性 'META',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30611089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com