use Excel Make website database .python The library used is Django、xlrd、xlrw、xlutils.
Excel Read normal , You can extract table data into lists , You can pass the list data through
render The way in view.py To the corresponding html In the web page . The web page also received a list .
Want to pass table stay html Display the contents of the list on the , The grid of a table corresponds to a list value . But somehow after the output, the list value is split into a single character . What is the solution . Specifically, what went wrong .
view.py Render function returned from file ,ownerlist[0][1] It's a list , Pass it on to bms_work.html:
return render(request, 'bms_work.html',
{'company': company, 'name': name, 'ownerlist': ownerlist[0][1], 'sh_rnlist': ownerlist[1]})
bms_work.html The tag statements in are as follows :
<tr> <td width="300px"> {% for item1 in ownerlist %} {
{ item1 }} </td></tr>{% endfor %}
###### Operation results and error reporting contents One grid, one list value
you ownerlist[0][1] Is a string , Use eval(ownerlist[0][1]) Convert to list
Do you use Excel Make website database ,Excel Only numeric values or strings can be stored in a cell , When you store the list in a cell, you turn the list into a string
you view.py Used in documents
print(type(ownerlist[0][1]))
See if it is a string str object
If yes render() Medium to 'ownerlist': eval(ownerlist[0][1])
return render(request, 'bms_work.html',{
'company': company, 'name': name, 'ownerlist': eval(ownerlist[0][1]), 'sh_rnlist': ownerlist[1]})