Reputation: 1
I am writing a simple code to fetch the variable from HTML file. Here is my code:
views.py file
def VariableView(request):
context = {'firstName: Muhammad' , 'lastName: Khan'}
return render(request, 'Variable.html',context)
Variable.html file:
<body>
<h1>VARIABLE.HTML</h1>
<h2>{{firstName | upper}}</h2>
</body>
I get an error at my console:
TypeError at /MyApp/variable/
context must be a dict rather than set.
Request Method: GET
Request URL: http://127.0.0.1:8000/MyApp/variable/
Django Version: 3.2
Exception Type: TypeError
Exception Value:
context must be a dict rather than set.
Exception Location: C:\Users\DELL\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\django\template\context.py, line 268, in make_context
Python Executable: C:\Users\DELL\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe
Python Version: 3.7.9
Python Path:
['C:\\Users\\DELL\\Desktop\\DJango\\mysite',
'C:\\Program '
'Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\\python37.zip',
'C:\\Program '
'Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\\DLLs',
'C:\\Program '
'Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\\lib',
'C:\\Program '
'Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0',
'C:\\Users\\DELL\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python37\\site-packages',
'C:\\Program '
'Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.2544.0_x64__qbz5n2kfra8p0\\lib\\site-packages']
Server time: Fri, 29 Jul 2022 08:23:36 +0000
Upvotes: 0
Views: 91
Reputation: 771
As stated in error message, you forget 4 '
def VariableView(request):
context = {'firstName': 'Muhammad' , 'lastName': 'Khan'}
return render(request, 'Variable.html',context)
Upvotes: 1