【发布时间】:2016-08-01 01:39:17
【问题描述】:
目标:使用Django:1.9.4,Python:2.7,使用Django 框架从Bugzilla 数据库中检索错误用于分析目的
函数调用函数(view.py)
@login_required(login_url='login/')
def customerBugs(request):
tag_id = request.GET['tag_id']
request.session['tagid'] = tag_id
tag_id = int(tag_id)
customer_names = {1:'Customer1', 2:'Customer2', 3:'Customer3'}
tag_name = customer_names[tag_id]
request.session[0] = tag_name
listbugs1 = list(listBugs(tag_name, request))
return render(request, 'customerbugs.html', {'listbugs1': listbugs1, 'tag_name': tag_name})
获取详细信息的函数 (bugzilla.py)
def listBugs(tag_id,request):
db = MySQLdb.connect(host=DBhost, port=DBport, user=DBuser, passwd=DBpassword , db=DBdatabase)
sql1 = ('SELECT bug_id, short_desc, bug_status FROM bugzilla.bugs WHERE cf_customer_name = "%s"' %tag_id)
cursor = db.cursor()
cursor.execute(sql1)
data2 = cursor.fetchall()
db.close()
print data2
return data2
以少量细节显示错误 (displayBugs.html)
{% extends 'base.html' %}
{% block content %}
<form method="" action="/downloadReport/">
<button type="submit" name="tag_id" value="{{request.session.tagid }}">Download</button>
</form>
<form method="get" action="/customerBugStatus/">
<button type="submit" style="float: right;" name="status_id" value="Open">Open Bugs
</button>
</form>
<table border="1" style="width:100%">
<h2> Customer name: {{ tag_name }}</h2>
<tr>
<th>Bug ID</th>
<th>Dscription</th>
<th>Status</th>
</tr>
{% for bug in listbugs1 %}
<tr>
<td>
{{ bug.0 }}</a>
</td>
<td>
{{ bug.1 }}</a>
</td>
<td>
{{ bug.2 }}</a>
</td>
</tr>
{% endfor %}
{% endblock %}
除了一种情况外,它可以按要求正常工作:
错误总结
1.8 – 加载日历:当用户尝试通过 URL 加载日历时显示操作错误。
在1.8 之后,它应该是连字符(-),但不是,\x96 在检索时。
抛出错误:
DjangoUnicodeDecodeError at /customerBugs/
'utf8' codec can't decode byte 0x96 in position 4: invalid start byte. You passed in '1.8 \x96 Load Calendar: Operational Error displayed when user is trying to load calendar via URL.' (<type 'str'>)
请求帮助我如何解码这个字符,尝试了很多链接,但没有运气,非常感谢帮助。
【问题讨论】:
标签: mysql python-2.7 utf-8 decode django-1.9