Error: unhashable type: dict

2024/11/19 3:27:22

i have a problem with Django: I can't show the data from mysql database in the table. I see the error "Exception Value: unhashable type: 'dict'" This is my code: views.py:

List_of_date=El.objects.all()
return HttpResponse(template.render(context),args, {'List_of_date': List_of_date})

models.py:

class El(models.Model):id_ch=models.IntegerField()TXT = models.CharField(max_length=200) 

Template:

<table><thead><tr><th>№</th><th>Text</th></tr></thead><tbody>{% for i in List_of_date %}<tr><td class="center">{{ i.id_ch }}</td><td class="center">{{ i.TXT }}</td></tr>{% endfor %}</tbody></table>

Can anybody help me?

Answer

You are passing bad arguments to HttpResponse constructor signature is

HttpResponse.__init__(content='', content_type=None, status=200, reason=None, charset=None)

and I thinks you want to use {'List_of_date': List_of_date} as context for template render. So you rather want call something like (i don't know what menas your args variable)

return HttpResponse(template.render(Context({'List_of_date': List_of_date})))
https://en.xdnf.cn/q/118591.html

Related Q&A

terminal command line python3.3

Im following a book tutorial and its telling me to install python3.3 with the command linesudo apt-get install python3.3however Im getting errorsUnable to locate package python3.3 Couldnt find any pack…

SQLalchemy making errors after being updated to 1.4.0 [duplicate]

This question already has answers here:ImportError: cannot import name _ColumnEntity from sqlalchemy.orm.query(5 answers)ImportError: cannot import name _ColumnEntity Ubuntu20.10 [duplicate](1 answer)C…

Python string formatting with percentage (TypeError: not enough arguments for format string)

The following code fails to run.It goes through a CSV file and retrieves the values and formats them in a array of tuples (a insert query) to be used later. Problem is the csv last column is sometimes …

Circles touching edges

I am struggling with a program to tell whether a created disk touches the edge of a predefined box. The parser keeps saying things such asNameError: global name disksdescription is not defined Warning…

How to split data from a merged cell into other cells in its same row of a Python data frame?

I have a sample of a data frame which looks like this: +---+--------------------------------------------------------------------------------------+---------------+--------------------------------------…

Collect data in chunks from stdin: Python

I have the following Python code where I collect data from standard input into a list and run syntaxnet on it. The data is in the form of json objects from which I will extract the text field and feed …

Getting and calculating stuff through tkinter widets

I was wondering how to calculate stuff using tkinter buttons. Im making a simple program to calculate seconds to hours:minutes:seconds. The user inputs an integer using the entry widget on the seconds …

Why does this condition execute to false when it should execute to true?

I have this code in my spider basic.py file:if l.add_xpath(price, //*[@id="price"]/text(),MapCompose(lambda i: i.replace(,, ), float),re = [,.0-9]):l.add_value(available, 1) else:l.add_value(…

Convert nested JSON to CSV in Python 2.7

Have seen a lot of thread but unable to found the solution for mine. I want to convert one nested JSON to CSV in Python 2.7. The sample JSON file is as below:sample.json # My JSON file that mainly cont…

How do I rectify this error: newline is invalid keyword argument for this function

Im currently working with raspberry pi and using DHT11 to read temperature and humidity values every second. I have to save these values into a database in real time. Heres my code that showing sensor …