Compare commits
2 Commits
75302a563a
...
11294a6c8c
| Author | SHA1 | Date | |
|---|---|---|---|
| 11294a6c8c | |||
| 19bf4fb293 |
@@ -62,7 +62,43 @@ handler403 = 'web.views.handler403'
|
||||
handler500 = 'web.views.handler500'
|
||||
|
||||
if settings.DEBUG:
|
||||
import mimetypes
|
||||
import debug_toolbar
|
||||
from django.views.static import serve
|
||||
|
||||
def _serve_public_root_file(request, path):
|
||||
"""Отдаёт файлы из корня `public` в dev-режиме в utf-8."""
|
||||
response = serve(request, path, document_root=settings.PUBLIC_DIR)
|
||||
content_type, _ = mimetypes.guess_type(path)
|
||||
if content_type:
|
||||
if content_type.startswith('text/'):
|
||||
response['Content-Type'] = f'{content_type}; charset=utf-8'
|
||||
else:
|
||||
response['Content-Type'] = content_type
|
||||
elif path.endswith('.txt'):
|
||||
response['Content-Type'] = 'text/plain; charset=utf-8'
|
||||
elif path.endswith('.html'):
|
||||
response['Content-Type'] = 'text/html; charset=utf-8'
|
||||
return response
|
||||
|
||||
def _iter_public_root_files():
|
||||
"""Находит все обычные файлы в корне `public`, кроме служебных артефактов."""
|
||||
for file_path in sorted(settings.PUBLIC_DIR.iterdir()):
|
||||
if not file_path.is_file():
|
||||
continue
|
||||
if file_path.name.startswith('.'):
|
||||
continue
|
||||
if file_path.name == 'README.md':
|
||||
continue
|
||||
yield file_path.name
|
||||
|
||||
PUBLIC_ROOT_URLPATTERNS = [
|
||||
path(filename, _serve_public_root_file, {'path': filename})
|
||||
for filename in _iter_public_root_files()
|
||||
]
|
||||
|
||||
urlpatterns = [path('__debug__/', include(debug_toolbar.urls)), ] + urlpatterns
|
||||
urlpatterns = [*PUBLIC_ROOT_URLPATTERNS, *urlpatterns]
|
||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.PUBLIC_DIR.joinpath('static'))
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
# urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
<meta name="generator" content="handcraft" />
|
||||
<title>CADpoint.ru - http 500 error</title>
|
||||
<meta name="theme-color" content="#F5F5F5" />
|
||||
<link rel="icon" type="image/svg+xml" href="/static/svgs/favicon.svg" />
|
||||
<link rel="icon" type="image/png" href="/static/img/favicon.png" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/static/img/favicon.ico" />
|
||||
<link rel="icon" type="image/svg+xml" href="/media/_error/svgs/favicon.svg" />
|
||||
<link rel="icon" type="image/png" href="/media/_error/img/favicon.png" />
|
||||
<link rel="shortcut icon" type="image/x-icon" href="/media/_error/img/favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
<div style="width:100%;height:80%;display:table;position:absolute;top:0;left:0;">
|
||||
<div style="display:table-cell;text-align:center;vertical-align:middle;">
|
||||
<div style="display:inline-block;">
|
||||
<img src="/static/svgs/cappoint_under_reconstruction.svg"
|
||||
<img src="/media/_error/svgs/cappoint_under_reconstruction.svg"
|
||||
alt="cadpoint.ru - under reconstruction" style="width: 80vw;"/>
|
||||
<pre>сайт cadpoint.ru реконструируется... подождите, скоро все вся станет не так как прежде...</pre>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user