我正在做本教程 - http://www.netmagazine.com/tutorials/get-started-django#requirements
到目前为止,我正试图浏览我的应用程序...
但我只得到:
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "C:\NetMagProjekt\netmag\blog\views.py" in index
8. return render(request, 'blog/index.html', {'posts': posts})
File "C:\Python27\lib\site-packages\django\shortcuts\__init__.py" in render
44. return HttpResponse(loader.render_to_string(*args, **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\filesystem.py" in load_template_source
39. 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 /
Exception Value: 'utf8' codec can't decode byte 0xa0 in position 26: invalid start byte
Settings.py:
TEMPLATE_DIRS = (
"C:/NetMagProjekt/netmag/netmag/Templates",
)
查看:
from django.shortcuts import render, get_object_or_404
from blog.models import Post
def index(request):
# get the blog posts that are published
posts = Post.objects.filter(published=True)
# now return the rendered template
return render(request, 'blog/index.html', {'posts': posts})
出于想法......任何想法?
答案 0 :(得分:3)
您的模板编码错误。将其保存为UTF-8。