For static file to work in django:
1. Update the model field:
uploaded_file = models.FileField(upload_to='one/static/uploaded_file/')
2. In settings.py
STATIC_URL = '/one/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'var','one/static')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "one/static"),
]
3. urls
from django.conf.urls.static import static
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
4.Run command
winpty docker exec -it demo_backend bash -c 'python3 manage.py collectstatic --noinput'
5. window.open(element.uploaded_file, '_blank'); //uploaded path, one/static/uploaded_file/..
Comments
Post a Comment