At the beginning I wanted to say hello and say that I have been using the portal for several years, but now I decided to create an account and describe my problem.
I try to display the table, unfortunately there is still an error when I open view.html:
UnicodeDecodeError at /add 'utf-8' codec can't decode byte 0xb3 in position 8: invalid start byte
For a few hours I was looking for a solution and unfortunately I could not solve this problem. I use Polish characters, in the database characters are saved as utf-8, if I remove the Polish characters from the database it all works, but that's not what I want.
models.py
from django.db import models
class komDane (models.Model):
data = models.TextField()
product = models.TextField()
oldprice = models.TextField()
newprice = models.TextField()
dostepnosc = models.IntegerField()
def __str__(self):
return self.name
views.py
from django.shortcuts import render, render_to_response
import mysql.connector
from .models import komDane
import sys
def index(request):
dupa = "nic"
return render_to_response('index.html', {'name':'dupa'})
def add(request):
zwraca = komDane.objects.all()
return render_to_response('result.html', {'dane': zwraca})
views.html
{% extends 'head1.html' %}
{% block content %}
<table><tbody>
{% for a in dane %}
<tr><td>{{ a.id }}</td><td>{{ a.product }}</td><td>{{ a.oldprice }}</td><td>{{ a.newprice }}</td><td>{{ a.newprice }}</td></tr>
{% endfor %}
</table></tbody>
{% endblock %}
error
Request URL: http://192.168.1.12:8001/add
Django Version: 2.2.6
Exception Type: UnicodeDecodeError
Exception Value:
'utf-8' codec can't decode byte 0xb3 in position 8: invalid start byte
Exception Location: /usr/local/lib/python3.5/dist-packages/MySQLdb/cursors.py in _fetch_row, line 325
Python Executable: /usr/bin/python3
Python Version: 3.5.3
Python Path:
['/home/pi/Desktop/mysite',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-arm-linux-gnueabihf',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages']
Server time: Wt, 5 Lis 2019 21:18:21 +0100
In database (5.5.62-cll - MySQL Community Server) utf8 is set per table and text field. Coding of server characters: UTF-8 Unicode.