Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

urlpatterns = [...]+static(settings.STATIC_URL) get the escape symbol

When I add STATIC_URL in the urls.py:

urlpatterns = [...]+static(settings.STATIC_URL)

but there I get the ^static\/(?P<path>.*)$ in the urls.

Shouldn't it be ^static/(?P<path>.*)$? like the ^media/(?P<path>.*)$.

enter image description here


in settings.py:

STATIC_URL = '/static/'

STATIC_ROOT = BASE_DIR + '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

How to solve this issue? or is there another way to replace the

+static(settings.STATIC_URL)

if has, provide to me for testing, thanks.

like image 225
user7693832 Avatar asked Nov 18 '22 16:11

user7693832


1 Answers

There is a way to avoid that issue. in the urls.py:

from django.conf.urls.static import serve

if settings.DEBUG:
    urlpatterns += [
        url(r'^static/(?P<path>.*)$', serve, {
            'document_root': settings.STATIC_ROOT
        })
    ] 

The result will like this:

^media/(?P<path>.*)$
^static/(?P<path>.*)$  # this is as the same with the media
like image 155
aircraft Avatar answered Dec 21 '22 00:12

aircraft