django TyoeError:context必须是dict而不是set

ergxz8rk  于 2023-08-08  发布在  Go
关注(0)|答案(1)|浏览(112)

当我输入127.0.0.1:8000/decore_detail/123 B/时,我想得到decore_detail.html。但是,我运行下面的配置代码,它向我报告错误。如何解决?“TyoeError:context必须是dict而不是set”

Traceback (most recent call last):
  File "C:\Users\daiyij\Anaconda3\envs\django\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\daiyij\Anaconda3\envs\django\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\decoredesigner\mySite\DecoreGenerator\views.py", line 14, in decore_detail
    return render(request,'decore_detail.html',{'decore_detail',decore_detail})
  File "C:\Users\daiyij\Anaconda3\envs\django\lib\site-packages\django\shortcuts.py", line 24, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "C:\Users\daiyij\Anaconda3\envs\django\lib\site-packages\django\template\loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "C:\Users\daiyij\Anaconda3\envs\django\lib\site-packages\django\template\backends\django.py", line 57, in render
    context = make_context(
  File "C:\Users\daiyij\Anaconda3\envs\django\lib\site-packages\django\template\context.py", line 278, in make_context
    raise TypeError(

Exception Type: TypeError at /decore_detail/7520N/
Exception Value: context must be a dict rather than set.

字符串
urls.py:

from myapp.views import decore_detail

urlpatterns = [
    path('admin/', admin.site.urls),
    path('decore_detail/<str:decore_detail>/',views.decore_detail,name='decore_detail'),
]


views.py:

def decore_detail(request,decore_detail):
    context = {"decore_detail": decore_detail}
    return render(request,'decore_detail.html',{'decore_detail',decore_detail})


decore_detail.py:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  
  <title>Item Detail</title>
  
</head>

<body>
  <h1>Item Detail - {{decore_detail}}</h1>
  
</body>

</html>

fwzugrvs

fwzugrvs1#

你可能想做这样的事情:
网址:Views.py

def decore_detail(request,decore_detail):
    context = {"decore_detail": decore_detail}
    return render(request,'decore_detail.html', context)

字符串

相关问题