第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

/ context 處的 TypeError 必須是 dict 而不是 RequestContext

/ context 處的 TypeError 必須是 dict 而不是 RequestContext

富國滬深 2022-05-24 16:09:43
我有一個基于 Django 1.9 構(gòu)建的應(yīng)用程序,但現(xiàn)在我已將其升級到 2.2。好吧,我遇到了一個奇怪的錯誤,我無法使用現(xiàn)有的類似解決方案來解決它。在我的例子中,我們從一個不同的文件中獲取 templateResponse 然后是內(nèi)置的[說 x.py]-class TemplateResponse(DefaultResponse):"""A normal response involving data that can be sent to fill in atemplate.  Since the template is specific to HTML responses, whena JSON response is desired, this class is indistinguishablefrom DefaultResponse."""def __init__(self, template, data, status=200):    self.data = data    self.template = template    self.status = status[基礎(chǔ).py]-def home(guts):     return TemplateResponse(template, {'c_sk': c_nt,                                   'd_sk_count': d_sk_count} 回溯錯誤 -response = get_response(request) …? Local vars/home/gaurav/Desktop/a Upgrade Work/a/new_cl/lib/python3.6/site-packages/django/core/handlers/base.py in _get_response                response = self.process_exception_by_middleware(e, request) …    ? Local vars /home/gaurav/Desktop/a Upgrade Work/a/new_cl/lib/python3.6/site-packages/django/core/handlers/base.py in _get_response                response = wrapped_callback(request, *callback_args, **callback_kwargs) …    ? Local vars/usr/lib/python3.6/contextlib.py in inner                return func(*args, **kwds) …    ? Local vars/home/gaurav/Desktop/a Upgrade Work/a/new_cl/lib/python3.6/site-packages/django/contrib/auth/decorators.py in _wrapped_view                return view_func(request, *args, **kwargs) …    ? Local vars/home/gaurav/Desktop/a Upgrade Work/a/main/x.py in g            response = seed.sprout(context, format) …    ? Local vars/home/gaurav/Desktop/a Upgrade Work/a/main/x.py in sprout            return self.sprout_html(context) …    ? Local vars/home/gaurav/Desktop/a Upgrade Work/a/main/x.py in sprout_html        body = self.template.render(context) …    ? Local vars
查看完整描述

2 回答

?
慕標(biāo)琳琳

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超9個贊

我通過更改下面提到的代碼解決了這個問題 -


def home(guts): 

  return TemplateResponse(template.render(mt_context1)) 

但是,這又引入了另一個錯誤。


不確定我是否可以在這里發(fā)布這個問題,但由于它似乎與此有關(guān),我在下面提到它,任何對此的專業(yè)人士,我真的可以使用一些建議:)


追溯:


File "/home/gaurav/Desktop/a scratch/onenv/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner

34.             response = get_response(request)


File "/home/gaurav/Desktop/a scratch/onenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response

115.                 response = self.process_exception_by_middleware(e, request)


File "/home/gaurav/Desktop/a scratch/onenv/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response

113.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)


File "/usr/lib/python3.6/contextlib.py" in inner

52.                 return func(*args, **kwds)


File "/home/gaurav/Desktop/a scratch/onenv/lib/python3.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view

21.                 return view_func(request, *args, **kwargs)


File "/home/gaurav/Desktop/a scratch/a/main/wrapper.py" in g

339.                 seed = d[request.method](guts, *args, **kwargs)


File "/home/gaurav/Desktop/a scratch/a/main/wrapper.py" in <lambda>

367.     return dispatch_on_method(f, {"GET": lambda guts, *args, **kwargs: f(guts, *args, **kwargs)})


File "/home/gaurav/Desktop/a scratch/a/main/views/base.py" in home

104.     return TemplateResponse(template.render(mt_context1))

異常類型:TypeError at / 異常值:init()缺少1個必需的位置參數(shù):'data'


查看完整回答
反對 回復(fù) 2022-05-24
?
largeQ

TA貢獻(xiàn)2039條經(jīng)驗(yàn) 獲得超8個贊

您應(yīng)該將傳入請求傳遞給 TemplateResponse

def home(request):
    response = TemplateResponse(request, 'mytemplate.html', {'c_sk': c_nt,'d_sk_count': d_sk_count} )
        return response


查看完整回答
反對 回復(fù) 2022-05-24
  • 2 回答
  • 0 關(guān)注
  • 149 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號