1

I am trying to package a django application which also contains script files(angularJS). When I create an exe , its not able to load the static files(404 error). I tried python manage.py collectstatic and its copying the files from the correct location. But when I run the exe, its not able to load the files.

Theres a related question,but that solution didnt solve the problem.Location of static files when creating a Django exe using pyinstaller

My settings.py file

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/res/'
STATIC_ROOT = os.path.join(BASE_DIR, "res")
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'Rule/res'),
)

My spec file:

added_files = [
     ('Rule\\templates\\*.html','Rule\\templates'),
     ('Rule\\migrations','Rule\\migrations'),
     ('Rule\\res\\scripts\\*.js','Rule\\res\\scripts'),
     ]

Its able to load the templates, but not the script files.

I am loading the script files in my html file like this:

{% block js %}
<script src='{% static "scripts/app.js" %}' ></script>
<script src='{% static "scripts/angular.js" %}'></script>
<script src='{% static "scripts/angular-ui-router.js" %}'></script>
<script src='{% static "scripts/angular-route.min.js" %}'></script>
<script src="{% static "scripts/ui-grid.min.js" %}"></script>

{% endblock %}

Please help me if I am missing something.Thanks

Community
  • 1
  • 1

1 Answers1

1

Please take a look at this: Managing static files (e.g. images, JavaScript, CSS)

In your urls.py file, you should add something like the following:

from django.conf import settings

from django.conf.urls.static import static

urlpatterns = [
url(r'^login$', login, name='login'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
appa yip yip
  • 1,404
  • 1
  • 17
  • 38
yixing yan
  • 173
  • 1
  • 7