Repository URL to install this package:
|
Version:
0.0.1 ▾
|
dj-kaos-react
/
views.py
|
|---|
import re
from django.conf import settings
from django.http import HttpResponse
from django.shortcuts import redirect
from django.views.generic import View
class ReactAppView(View):
def get(self, request):
try:
index_path = str(settings.REACT_APP_DIR.path('index.html'))
with open(index_path) as file:
return HttpResponse(file.read())
except FileNotFoundError:
return HttpResponse(
"""
index.html not found! Build your React app!!
""",
status=501,
)
def react_static_redirect(request):
match = re.match(f"^/{settings.REACT_HOME}(.*)", request.path)
if match:
return redirect(match.groups()[0])
return redirect(request.url)