S
S
Sergey Pashkevich2015-07-25 18:02:02
Django
Sergey Pashkevich, 2015-07-25 18:02:02

Django. How to include static files outside the project?

Good time. There was a problem with including static files in the Django & Angular bundle. When including a js file, Django can't find files outside the project. The structure of the project is shown in the image. Two projects lie next to Django (api) & Angular (web) and all static files are stored in the web / public folder, how can I access static files from the api folder? e808eaede5e5432d9531071f6dae2467.png
Some code:
settings.py

...
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    '/home/alice/projects/listify/web/public',
)

urls.py(main):
urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^', include('index.urls', namespace='index')),
]

urls.py(index application):
urlpatterns = [
    url(r'^$', views.index, name='index'),
]

views.py(index application):
def index(request):
    return render(request, 'index.html', {})

index.html:
{% load staticfiles %}

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Listify</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <script type="text/javascript" src="{% static 'public/js/lib.js' %}"></script>

    </head>
    <body>
        <ui-view></ui-view>
    </body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2015-07-25
@siarheipashkevich

django doesn't need to know anything about the front at all

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question