1

I put static files under a app directory which is related to the static files.

for example,

image.jpg is used for templates under exmapleapp. so I locate image.jpg file in a directory /project/exampleapp/static/image.jpg

In Debug=True settings, Dajngo finds static files automatically by django.contrib.staticfiles. If you put static files projoject directory /project/static/, you can set STATICFILES_DIRS = []in settings.py or add like urlspatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) in urls.py(if you want to serve static files manually)

so far, is nothing problem in development right? but you want to deploy, you need to do collectstatic. I am confused from now.

This is what I thought initially.

step1 : you work and test your code in local with DEBUG = True in setting. you continously save your code in git repo.

step2 : you are ready to deploy your code in server. you clone your repo and set apache server for running django framework properly(Alias static, WSGI Daemon process). you do python manage.py collectstatic to serve static file with apache server.

step3 : you keep work in local to improve your code and apply this improvement into your code in server with test.

I got confused and got questions.

Q1 : if you do collectstatic for deployment, there will be static folder(according to STATIC_ROOT settings) with all static files which is spread around in each app folders.

do you do collectstatic in local and send only the static folder which collects all to server? or do you do collectstatic in server according to Static Alias setting in Apache server?

Q2 : Do you change DEBUG = False and ALLOWED_HOSTS =[server IP] in local and save code in git repo and pull it in server??

well, now I am confused with working during development with github and deploying it to server with github with Django settings.

Tell me if you can't understand my question clearly please.

Sayse
  • 42,633
  • 14
  • 77
  • 146
Jayground
  • 1,797
  • 1
  • 17
  • 32

1 Answers1

1

You are using static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) for serving static files in development mode. But in production, (means DEBUG = False) it will be empty list. (static returns empty list). Then collectstatic, in you can use development or production.Its intention is to copy all static files to STATIC_ROOT.So

Q1: Everyone do collectstatic on production to serve static files through webserver(Apache, Nginx)

Q2: For production and development write different settings file. You can see here for ex How to manage local vs production settings in Django?

Community
  • 1
  • 1
itzMEonTV
  • 19,851
  • 4
  • 39
  • 49