Django无法加载Bootstrap Modal:UnicodeDecodeError

时间:2013-01-02 14:45:19

标签: python django twitter-bootstrap django-forms django-templates

假设我有一个简单的Django视图和模板(没什么复杂的)。只需将数据库中的一些数据渲染到模板上(我正在使用bootstrap项目)

现在,我希望在页面上添加一个表格(比如联系表格)。我想使用Bootstrap Modal功能,点击一个按钮,模式将切换到页面上(这里是一个联系表格)。

对于初始测试,我刚刚复制了示例代码:

<!-- Button to trigger modal -->
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>

<!-- Modal -->
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Modal header</h3>
  </div>
  <div class="modal-body">
    <p>One fine body…</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
</div>

然而,我发现的是:

当我只删除内部模态所需的HTML时,它正在工作。

等等。

           

    <h3 id="myModalLabel">Modal header</h3>
  </div>
  <div class="modal-body">

  </div>
  <div class="modal-footer">

  </div>
</div>

由于它只是模板编辑,我刷新页面并找到 UnicodeDecodeError

Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "D:\Code\Projects-Dev\cloudnote\note\views.py" in home
  21.     return render_to_response('home.html', context)
File "C:\Python27\lib\site-packages\django\shortcuts\__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "C:\Python27\lib\site-packages\django\template\loader.py" in render_to_string
  169.         t = get_template(template_name)
File "C:\Python27\lib\site-packages\django\template\loader.py" in get_template
  145.     template, origin = find_template(template_name)
File "C:\Python27\lib\site-packages\django\template\loader.py" in find_template
  134.             source, display_name = loader(name, dirs)
File "C:\Python27\lib\site-packages\django\template\loader.py" in __call__
  42.         return self.load_template(template_name, template_dirs)
File "C:\Python27\lib\site-packages\django\template\loader.py" in load_template
  45.         source, display_name = self.load_template_source(template_name, template_dirs)
File "C:\Python27\lib\site-packages\django\template\loaders\app_directories.py" in load_template_source
  57.                     return (file.read().decode(settings.FILE_CHARSET), filepath)
File "C:\Python27\lib\encodings\utf_8.py" in decode
  16.     return codecs.utf_8_decode(input, errors, True)

Exception Type: UnicodeDecodeError at /app/home/
Exception Value: 'utf8' codec can't decode byte 0xd7 in position 6904: invalid continuation byte

代码出错的地方以及如何修复它?

0 个答案:

没有答案