0

I have Django 1.11 project structure like this:

  • project
    • static
      • img1.png
    • app
      • static
        • img2.png

File "settings.py" contains:

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

Images are available at:

my-site.com/static/img1.png
my-site.com/static/img2.png

But I want the images to be available in a different way:

my-site.com/app/static/img1.png
my-site.com/app/static/img2.png

I can write to a file "project/app/urls.py":

urlpatterns += static('static/', document_root=os.path.join(BASE_DIR, 'app' + STATIC_URL))

And then "img2.png" will be available, but not "img1.png". How can I make "img1.png" available?

WayMax
  • 87
  • 9

1 Answers1

0

Here, try this...

urlpatterns += static('app/static/', document_root=os.path.join(BASE_DIR, STATIC_URL))
Chymdy
  • 662
  • 4
  • 14
  • If I write in the file "project/app/urls.py": urlpatterns += static('app/static/', document_root=os.path.join(BASE_DIR, STATIC_URL)) But the file "img1.png" is still not available. I can write: urlpatterns += static('static/', document_root=os.path.join(BASE_DIR, STATIC_URL)) And then the file "img1.png" will be available, but "img2.png" will not be available. – WayMax Apr 22 '22 at 08:49
  • If the file "project/app/urls.py" contains: urlpatterns += static('static/', document_root=os.path.join(BASE_DIR, 'app' + STATIC_URL)) And the file "project/project/urls.py" contains: urlpatterns += static('app/static/', document_root=os.path.join(BASE_DIR, STATIC_URL)) Also, one image is available, and the second is not available. – WayMax Apr 22 '22 at 08:59
  • Your static file url should be in project config folder not in any app (the folder where settings.py resides). – Chymdy Apr 23 '22 at 11:06