Django 修复 UnicodeDecode 错误解码

时间:2020-12-30 21:59:09

标签: javascript django

我正在关注 Django CRUD 教程,当我尝试加载我的 url 时出现此错误。除了这个之外,我的其余视图都有效,而且我以前从未见过这个错误。我在谷歌上搜索了类似的问题并找到了一些建议的解决方案(发布在下面),但对我来说没有任何效果。

任何想法如何解决这个问题?

我已经尝试添加 from __future__ import unicode_literals

def __str__(self):
   return "(%s)" % self.name

进入我的 views.py 文件,没有运气

'utf-8' codec can't decode byte 0xd7 in position 2046: invalid continuation byte

html

{% extends 'base.html' %}
{% load static %}

{% block title %}Django Ajax CRUD{% endblock %}

{% block content %}
<div class="container">
    <h1>Django Ajax CRUD</h1>
    <div class="row">
        <div class="col-md-4 ">
            <h3>ADD USER</h3>
            <form id="addUser" action="">
                <div class="form-group">
                    <input class="form-control" type="text" name="name" placeholder="Name" required>
                </div>
                <div class="form-group">
                    <input class="form-control" type="text" name="address" placeholder="Address" required>
                </div>
                <div class="form-group">
                    <input class="form-control" type="number" name="age" min="10" max="100" placeholder="Age" required>
                </div>
                <button class="btn btn-primary form-control" type="submit">SUBMIT</button>
            </form>
        </div>
        <div class="col-md-8">
            <h3>USERS</h3>
            <table id="userTable" class="table table-striped">
                <tr>
                    <th>Name</th>
                    <th>Address</th>
                    <th colspan="3">Age</th>
                </tr>
                {% if users %}
                {% for user in users %}
                <tr id="user-{{user.id}}">
                    <td class="userName userData" name="name">{{user.name}}</td>
                    <td class="userAddress userData" name="address">{{user.address}}</td>
                    <td class="userAge userData" name="age">{{user.age}}</td>
                    <td align="center">
                        <button class="btn btn-success form-control" onClick="editUser({{user.id}})" data-toggle="modal" data-target="#myModal" )">EDIT</button>
                    </td>
                    <td align="center">
                        <button class="btn btn-danger form-control" onClick="deleteUser({{user.id}})">DELETE</button>
                    </td>
                </tr>
                {% endfor %}
                {% else %}
                No Users
                {% endif %}
            </table>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="myModalLabel">Update User</h4>
            </div>
            <form id="updateUser" action="">
                <div class="modal-body">
                    <input class="form-control" id="form-id" type="hidden" name="formId" />
                    <label for="name">Name</label>
                    <input class="form-control" id="form-name" type="text" name="formName" />
                    <label for="address">Address</label>
                    <input class="form-control" id="form-address" type="text" name="formAddress" />
                    <label for="age">Age</label>
                    <input class="form-control" id="form-age" type="number" name="formAge" min=10 max=100 />
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">Save changes</button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}
{% block javascript %}
{% endblock javascript %}

基础

{% load static %}
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>{% block title %}Title{% endblock title %}</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    {% block stylesheet %}{% endblock stylesheet %}
</head>
<body>
    <main>
        {% block content %}
        {% endblock content %}
    </main>
    <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
    <script src='https://code.jquery.com/jquery-3.2.1.min.js'></script>
    <script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script>
    {% block javascript %}
    {% endblock javascript%}
</body>
</html>

0 个答案:

没有答案