How to make files available not in "/static/", but in "/app/static/"?

32 views Asked by At

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?

1

There are 1 answers

3
Chymdy On

Here, try this...

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