1 | from django.conf import settings
|
---|
2 | from django.conf.urls.static import static
|
---|
3 | from django.urls import get_script_prefix
|
---|
4 | from django.contrib.staticfiles.views import serve
|
---|
5 | import sys
|
---|
6 | urlpatterns = []
|
---|
7 |
|
---|
8 |
|
---|
9 | def staticfiles_urlpatterns(prefix=None):
|
---|
10 | """
|
---|
11 | Helper function to return a URL pattern for serving static files.
|
---|
12 | """
|
---|
13 | if prefix is None:
|
---|
14 | prefix = settings.STATIC_URL
|
---|
15 | tmp_script_prefix = get_script_prefix()
|
---|
16 | if len(tmp_script_prefix) > 1 and prefix.startswith(tmp_script_prefix):
|
---|
17 | l1 = len(tmp_script_prefix)
|
---|
18 | oldprefix = prefix
|
---|
19 | prefix = prefix[l1:]
|
---|
20 | return static(prefix, view=serve)
|
---|
21 |
|
---|
22 |
|
---|
23 | # Only append if urlpatterns are empty
|
---|
24 | if settings.DEBUG and not urlpatterns:
|
---|
25 | urlpatterns += staticfiles_urlpatterns()
|
---|