-2

I tried all the ways to deploy static files in production environment but still the static files are not appearing. I don't know whats wrong.

Please help me in deploying static files(like css, javascripts, images, etc.).

I've tried using many different ways from many sources.But all in vain

Is there any easy way or can you please explain the traditional ways. Can you please explain the steps that you followed?

  • Stack overflow isn't the right place for your blog entry. – Sayse Sep 01 '15 at 10:57
  • Also, theres a giant warning in settings.py ... `# SECURITY WARNING: don't run with debug turned on in production!"` so your step 2 should be done anyway – Sayse Sep 01 '15 at 10:59
  • 1
    This isnt my blog. Atleast you should have checked this :) . I felt difficulty in this thing. Just sharing with the people to make it easy for them too... – Sukhpreet Singh Sep 01 '15 at 10:59
  • But that implies they have the problem too, in which case they would be able to write their own question. Presumably stating why `collectstatic` didn't work for them – Sayse Sep 01 '15 at 11:01
  • I know about Keeping Debug = False. Just mentioning for the newbies who may forget to do this :). – Sukhpreet Singh Sep 01 '15 at 11:02
  • Please read http://stackoverflow.com/help/self-answer - even if you already know the answer, you should post as a proper question and answer, adhering to the same quality guidelines as if you were asking a question you didn't know the answer to and answering someone else's question. – jonrsharpe Sep 01 '15 at 11:03
  • Well you wont appreciate the right thing it seems :P Nevermind :) Ohk @Jonrshape. I will keep that in mind :) – Sukhpreet Singh Sep 01 '15 at 11:05
  • Don't just *"keep it in mind"*, please edit the question into an actual question (e.g. *"i tried all the ways to deploy static files but couldnt succeed"* is not specific enough) and add your own answer containing the answer. We do *"appreciate the right thing"*, but as it stands **this isn't it**. – jonrsharpe Sep 01 '15 at 11:06
  • @jonrsharpe - Normally, I'd agree but in this case there are [duplicates](http://stackoverflow.com/questions/8130182/django-and-staticfiles-questions) and this just seems to be advertising the github link.. – Sayse Sep 01 '15 at 11:07
  • @Sayse but then it can at least be closed as a dupe for the appropriate reason; it may still serve as a useful signpost in the correct format. – jonrsharpe Sep 01 '15 at 11:08
  • Ohk i will edit it :) – Sukhpreet Singh Sep 01 '15 at 11:08
  • Well i m just giving the direct link :) so it becomes easy for people to see it, follow it and implement it..:) – Sukhpreet Singh Sep 01 '15 at 11:10
  • Is it ok now? Hope i am following all the rules now. – Sukhpreet Singh Sep 01 '15 at 11:25

1 Answers1

1

At last i got an easy way to deploy static files in production environment. Therefore answering my own question.
For all the newbies like me who are feeling helpless in this case see this:-

https://github.com/kennethreitz/dj-static

1st Step: Install this using following command in terminal

$ sudo pip install dj-static


This is a simple Django middleware utility that allows you to properly serve static assets from production with a WSGI server like Gunicorn.


2nd Step:- Just set

#In settings.py file (to set production environment.)
Debug= False


3rd Step:- Configure your static assets in settings.py:

#add your path to STATIC_ROOT

STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'


4th Step:- And copy the lines written below and add them to wsgi.py
Do not remove any other lines. Just add these

from django.core.wsgi import get_wsgi_application
from dj_static import Cling

application = Cling(get_wsgi_application())


And its done. Now test it.


Note: Only using Apache(2.4) as web server. Nothing else to support apache.

Hope this helps other people too. if you have some more ways or simplified version of the traditional way please do share it.