kkteja
By:
kkteja

My Django/Python app is working only when I say Debug = True and that too static files are not loading

October 28, 2014 2.2k views

I am using ubuntu os and when I deployed my Django/Python app, it works only when I mention Debug=True. Apart from that when I start the server and navigate to browser I see that its not loading the static folder -any ideas?

3 Answers

When you set Debug=False you need to make sure that you've also set your domain and/or external IP address in ALLOWED_HOSTS. See the Django documentation:

When DEBUG is True or when running tests, host validation is disabled; any host will be accepted. Thus it’s usually only necessary to set it in production.

  • Yeah that thing is taken care off - I tried this ALLOWEDHOSTS = ['*'] & ALLOWEDHOSTS = ['127.0.0.1']. I also tried the IP that was assigned for the droplet, even then it simply throws error.

Hi,

You need to post more info: did you run ./manage.py collectstatic? What is in your settings.py, especially the STATIC_FILES setting? How are u using the image reference in your template? Are you using {% load staticfiles %} and then use {% static 'myimgpath' %}? Are your static files supposed to be hosted on the same instance your app is running?

  • fixed it, this is because of the conflict between STATIC_ROOT = /static/ in settings.py and configuration in /etc/nginx/sites-enabled/django file, remove this part and do not forget to restart the service with service nginx restart location /media { alias /home/django/supchang/media; } location /static { alias /home/django/ssupchang/static; }

fixed it, this is because of the conflict between STATIC_ROOT = /static/ in settings.py and configuration in /etc/nginx/sites-enabled/django file, remove this part and do not forget to restart the service with service nginx restart location /media { alias /home/django/supchang/media; } location /static { alias /home/django/ssupchang/static; }

Have another answer? Share your knowledge.