Future proof for filesystem encoding changing in the future

This commit is contained in:
Martin Green 2022-06-18 23:43:21 +01:00
parent 59a45871fd
commit f0cfed2ef6

View File

@ -19,6 +19,9 @@ from troggle.core.models.caves import Cave
import troggle.core.views.caves
import troggle.settings as settings
import sys
sysdefaultencoding = sys.getdefaultencoding()
'''Formerly a separate package called 'flatpages' written by Martin Green 2011.
This was NOT django.contrib.flatpages which stores HTML in the database, so the name was changed to expopages.
Then it was incorporated into troggle directly, rather than being an unnecessary external package.
@ -224,7 +227,7 @@ def expopage(request, path):
try:
t = type(filetobeopened)
content = open(filetobeopened.encode('utf8'), "rb")
content = open(filetobeopened.encode(sysdefaultencoding), "rb")
content_type=getmimetype(path)
return HttpResponse(content = content, content_type=content_type)
except IOError: