diff --git a/Dockerfile b/Dockerfile index a3dd4a37..5cf8638f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,6 +58,7 @@ VOLUME /data ENV DATABASE_URL="sqlite:////data/doccano.db" ENV DEBUG="False" +ENV STANDALONE="True" ENV SECRET_KEY="change-me-in-production" ENV PORT="8000" ENV WORKERS="2" diff --git a/backend/app/urls.py b/backend/app/urls.py index 828098c5..87701384 100644 --- a/backend/app/urls.py +++ b/backend/app/urls.py @@ -13,15 +13,17 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +import os +import re + from django.conf import settings -from django.conf.urls.static import static from django.contrib import admin from django.contrib.auth.views import TemplateView from django.urls import include, path, re_path +from django.views.static import serve from drf_yasg import openapi from drf_yasg.views import get_schema_view -# TODO: adds AnnotationList and AnnotationDetail endpoint. schema_view = get_schema_view( openapi.Info( title="doccano API", @@ -33,8 +35,15 @@ schema_view = get_schema_view( ) urlpatterns = [] -if settings.DEBUG: - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +if settings.DEBUG or os.environ.get('STANDALONE', False): + # For showing images and audios in the case of pip and Docker. + urlpatterns.append( + re_path( + r'^%s(?P.*)$' % re.escape(settings.MEDIA_URL.lstrip('/')), + serve, + {'document_root': settings.MEDIA_ROOT} + ) + ) urlpatterns += [ path('admin/', admin.site.urls), diff --git a/backend/cli.py b/backend/cli.py index 48fa0eca..ed8d2f3c 100644 --- a/backend/cli.py +++ b/backend/cli.py @@ -7,6 +7,7 @@ import sys from .app.celery import app os.environ['DEBUG'] = 'False' +os.environ['STANDALONE'] = 'True' base = os.path.abspath(os.path.dirname(__file__)) sys.path.append(base) manage_path = os.path.join(base, 'manage.py')