Browse Source

Enable to show images and audios in the case of pip and Docker

pull/1667/head
Hironsan 3 years ago
parent
commit
18daace617
3 changed files with 15 additions and 4 deletions
  1. 1
      Dockerfile
  2. 17
      backend/app/urls.py
  3. 1
      backend/cli.py

1
Dockerfile

@ -58,6 +58,7 @@ VOLUME /data
ENV DATABASE_URL="sqlite:////data/doccano.db" ENV DATABASE_URL="sqlite:////data/doccano.db"
ENV DEBUG="False" ENV DEBUG="False"
ENV STANDALONE="True"
ENV SECRET_KEY="change-me-in-production" ENV SECRET_KEY="change-me-in-production"
ENV PORT="8000" ENV PORT="8000"
ENV WORKERS="2" ENV WORKERS="2"

17
backend/app/urls.py

@ -13,15 +13,17 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
import os
import re
from django.conf import settings from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.views import TemplateView from django.contrib.auth.views import TemplateView
from django.urls import include, path, re_path from django.urls import include, path, re_path
from django.views.static import serve
from drf_yasg import openapi from drf_yasg import openapi
from drf_yasg.views import get_schema_view from drf_yasg.views import get_schema_view
# TODO: adds AnnotationList and AnnotationDetail endpoint.
schema_view = get_schema_view( schema_view = get_schema_view(
openapi.Info( openapi.Info(
title="doccano API", title="doccano API",
@ -33,8 +35,15 @@ schema_view = get_schema_view(
) )
urlpatterns = [] 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<path>.*)$' % re.escape(settings.MEDIA_URL.lstrip('/')),
serve,
{'document_root': settings.MEDIA_ROOT}
)
)
urlpatterns += [ urlpatterns += [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),

1
backend/cli.py

@ -7,6 +7,7 @@ import sys
from .app.celery import app from .app.celery import app
os.environ['DEBUG'] = 'False' os.environ['DEBUG'] = 'False'
os.environ['STANDALONE'] = 'True'
base = os.path.abspath(os.path.dirname(__file__)) base = os.path.abspath(os.path.dirname(__file__))
sys.path.append(base) sys.path.append(base)
manage_path = os.path.join(base, 'manage.py') manage_path = os.path.join(base, 'manage.py')

Loading…
Cancel
Save