0
votes

I have created a Django app and just deployed it to a server. I use some extra django features such as the django-debug-toolbar which was installed from my requirements.txt file using pip.

When I run my app locally, on localhost, everything works fine and the extra features are loaded successfully.

Here is the right structure of the sources loaded:

enter image description here

But when I run my app from the server for some reason the paths are not correct.

enter image description here

And in my browser's console I get these errors:

enter image description here

All these paths are from the installed packages like the django-debug-toolbar and it wouldn't make sense to change them. For example, the toolbar.js file is loaded with this command: <script src="{% static 'debug_toolbar/js/toolbar.js' %}"></script>

which can be found in the: lib/python2.7/site-packages/debug_toolbar/templates/debug_toolbar/base.html file, which was created after I installed all the packages from my requirements.txt file.

That should work fine. It does work fine when I run it locally, but it doesn't when I run on the new server. Any ideas?

1
Have you ran collectstatic? you should also try to post textual information as text instead of images - Sayse
Is it necessary to run collectstatic? I have copied the settings for INSTALLED_APPS and MIDDLEWARE_CLASSES and as I said it works fine when I run locally. Also, what textual information would you need for this issue? - Galil
It works locally because the static folder is the same, so yes collectstatic is probably needed. the textual information I refer to is your (relevant) console output - Sayse
@Sayse Thanks for your help! I ran collectstatic and I also made some changes on the paths as the STATIC_ROOT directory was not the same with the one set in the nginx conf file. Now it works fine! - Galil

1 Answers

1
votes

As mentioned in the comments, you need to call collectstatic when you make changes to the static files.

What this command does is copy the static files from their static folders to the location that you specify in your STATIC_ROOT directory, this should be the same as where nginx is looking for files.

The error you received is because those files weren't in the directory your nginx was looking in.