diff --git a/config/urls.py b/config/urls.py index 9d82d19..5e8a877 100644 --- a/config/urls.py +++ b/config/urls.py @@ -13,6 +13,7 @@ 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ + from django.conf import settings from django.conf.urls.static import static from django.urls import include, path @@ -21,4 +22,5 @@ urlpatterns = [ path("", include("services.urls")), path("", include("cms.urls")), + path(".well-known/", include("well_known.urls")), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/well_known/urls.py b/well_known/urls.py new file mode 100644 index 0000000..06b8290 --- /dev/null +++ b/well_known/urls.py @@ -0,0 +1,11 @@ +from django.urls import include, path + + +from .views import serve_text_file + + +urlpatterns = [ + path("pdi-pgp.asc", serve_text_file, {"file_name": "pdi-pgp.asc"}, name="pdi-pgp"), + path("security-policy.txt", serve_text_file, {"file_name": "security-policy.txt"}, name="security-policy"), + path("security.txt", serve_text_file, {"file_name": "security.txt"}, name="security"), +] diff --git a/well_known/views.py b/well_known/views.py new file mode 100644 index 0000000..dc53320 --- /dev/null +++ b/well_known/views.py @@ -0,0 +1,12 @@ +import os +from django.http import HttpResponse + + +def serve_text_file(request, file_name): + file_path = os.path.join('static', '.well-known', file_name) + try: + with open(file_path, 'r') as file: + content = file.read() + return HttpResponse(content, content_type='text/plain') + except FileNotFoundError: + return HttpResponse("File not found.", status=404) \ No newline at end of file