Goro
Goro

Reputation: 10249

In django, can I have multiple instances of static app?

Is it possible to have more than just one instance of the static app?

I have different types of resources that I might want to server from different STATIC_URL:

Upvotes: 1

Views: 1626

Answers (2)

user1151618
user1151618

Reputation:

Yes, it is possible.

I am using urls.py.

if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^docs/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/hdblog/docs'}),
        (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/hdblog/static'}),
    )

You should look at https://docs.djangoproject.com/en/dev/howto/static-files/?from=olddocs and https://docs.djangoproject.com/en/dev/howto/static-files/#serving-other-directories

Upvotes: 1

arie
arie

Reputation: 18982

I think you are a bit mistaken about the purpose of contrib.staticfiles:

In previous versions of Django, it was common to place static assets in MEDIA_ROOT along with user-uploaded files, and serve them both at MEDIA_URL. Part of the purpose of introducing the staticfiles app is to make it easier to keep static files separate from user-uploaded files.

PDF documents are probably user generated so ideally they are not stored side by side with your static files (css, js), but are uploaded to MEDIA_ROOT.

And in production you have to configure your web server to serve the directories under certain urls.

While in development however you can use django.views.static.serve to serve different dirs with different url prefixes.

Upvotes: 3

Related Questions