Changeset - 9fecb37c61f1
[Not reviewed]
0 1 0
Ben Sturmfels (bsturmfels) - 2 months ago 2024-03-06 08:02:00
ben@sturm.com.au
Update the path to templates in index()
1 file changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
conservancy/views.py
Show inline comments
...
 
@@ -3,12 +3,15 @@ import os.path
 

	
 
from django.http import HttpResponse
 
from django.template.response import TemplateResponse
 

	
 
from .local_context_processors import fundgoal_lookup
 

	
 
# This component doesn't actually have anything to do with Django's
 
# "staticfiles" app. It's only that its templates happen to be located in the
 
# STATIC_ROOT directory. They probably shouldn't be there.
 
STATIC_ROOT = os.path.abspath(os.path.dirname(__file__))
 
FILESYSTEM_ENCODING = 'utf-8'
 

	
 
def handler(request, errorcode):
 
    path = os.path.join('error', str(errorcode), 'index.html')
 
    fullpath = os.path.join(STATIC_ROOT, path)
...
 
@@ -30,13 +33,13 @@ def handler500(request):
 
    return handler(request, 500)
 

	
 
def index(request, *args, **kwargs):
 
    path = request.path.lstrip('/')
 
    if path.endswith('/'):
 
        path += 'index.html'
 
    fullpath = os.path.join(STATIC_ROOT, path)
 
    fullpath = os.path.join(STATIC_ROOT, 'static', path)
 
    try:
 
        # Junk URLs in production (Python 3.5) are causing UnicodeEncodeErrors
 
        # here. Can't reproduce in development in Python 3.9 - only Python 2.7.
 
        if not os.path.exists(fullpath):
 
            return handler404(request)
 
    except UnicodeEncodeError:
0 comments (0 inline, 0 general)