PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] Why gunicorn cannot find static files?

 November 08, 2022     digital-ocean, django, gunicorn, nginx, python     No comments   

Issue

Running Django dev server has no problem: 'python manage.py runserver 9000' But if use gunicorn, it complains:

'http://innovindex.com/pubmed/static/js/jquery-3.2.1.min.js '

Why gunicorn cannot find a local jquery but Django can?

The settings are:

settings.py (seems not related):

STATIC_URL = '/pubmed/static/'

in '/etc/nginx/sites-enabled/django'

location /static {
   alias /home/django/innovindex/pubmed/static/;
}

And my app looks like this:

/home/django/innovindex

is where the 'manage.py' sits.

THANK YOU SO MUCH !!!


Solution

From Deploying static files in the Django documentation, you must run the collectstatic command in addition to setting the STATIC_ROOT setting.

First make sure that you're STATIC_ROOT is set to the correct path that matches your nginx config:

STATIC_ROOT = '/home/django/innovindex/pubmed/static/'

Note that this is an absolute path.

Then run:

python manage.py collectstatic

in your project directory.

This will copy all of your static files into /home/django/innovindex/pubmed/static/



Answered By - roob
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,213,927

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing