Check this

http://stackoverflow.com/questions/7650893/serving-static-files-on-my-own-server/7651021#7651021


On Oct 4, 4:14 am, Mike Dewhirst <[email protected]> wrote:
> On 3/10/2011 10:00pm, Gelonida N wrote:
>
> > On 09/26/2011 10:21 PM, nara wrote:
> >> I am having trouble getting STATICFILES to work. I have read the docs,
> >> and followed the instructions, but I never get my css files to load.
> >> My current workaround is to put all the css inline in my template
> >> file, but that should not be a permanent solution.
>
> Here is a bit of my own interpretation which seems to work ...
>
> Project layout ... [0]
>
> projroot                PROJECT_ROOT [1]
> === === === === === === === === === === === === === === === === ===
> --- creds               project credentials non-versioned for security
> --- htdocs              production webserver document root [2]
> --- --- static          all collected static files - STATIC_ROOT [3]
> --- --- --- app1        app1 static files root
> --- --- --- --- css     app1 css
> --- --- --- --- images  app1 static images
> --- --- --- --- js      app1 javascript
> --- --- --- app2        app2 static files root
> --- --- --- --- css     app2 css
> --- --- --- --- images  app2 static images
> --- --- --- --- js      app2 javascript
> --- --- media           content-related media - MEDIA_ROOT [4]
> --- --- --- app1        app1 content media root
> --- --- --- --- images  app1 content images
> --- --- --- --- videos  app1 content videos
> --- --- --- app2        app2 content media root
> --- --- --- --- images  app2 content images
> --- --- --- --- videos  app2 content videos
>
> --- PROJECT             SRC_ROOT  (for urls.py, settings.py etc) [5]
> --- --- app1            app1 source (models.py etc)
> --- --- --- locale      app1 root for i18n/i10n translations/formats
> --- --- --- static      app1 static files root [6]
> --- --- --- --- css     app1 default stylesheets
> --- --- --- --- js      app1 javascript
> --- --- --- templates   app1 templates (eg base_app.html)
> --- --- --- tests       app1 unit tests
> --- --- app2            app2 source (models.py etc)
> --- --- --- locale      app2 root for i18n/i10n translations/formats
> --- --- --- static      app2 static files root [6]
> --- --- --- --- css     app2 default stylesheets
> --- --- --- --- js      app2 javascript
> --- --- --- templates   app2 templates (eg base_app.html)
> --- --- --- tests       app2 unit tests
> --- --- static          project static files - STATICFILES_DIR [7][8]
> --- --- --- css         project stylesheets (eg project.css)
> --- --- --- images      project (static, not-content) images
> --- --- --- js          project javascript libraries
> --- --- templates       project templates (base.html)
> --- --- --- admin       admin (base_site.html for branding admin)
> --- --- wsgi-bin        wsgi script dir [8]
>
> [0] This is my preference. It isn't mandated by Django.
> [1] Convenience only - not a Django setting
> [2] Not used in development only in production
> [3] Don't put anything here - use manage.py collectstatic instead [10]
> [4]https://docs.djangoproject.com/en/dev/ref/settings/#media-root
> [5] Convenience only - not a Django setting [9]
> [6]https://docs.djangoproject.com/en/dev/howto/static-files/#basic-usage
> [7]https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#static...
> [8]http://code.google.com/p/modwsgi/wiki/InstallationInstructions
>
> Static Files
> ============
>
> Provided 'django.contrib.staticfiles' is in INSTALLED_APPS, static files
> kept in two standard locations ...
>
>   - project/<app>/static (if different app static files are needed)
>   - project/static (actually, any directories in STATICFILES_DIRS)
>
> ... will be automatically found and served by the development server at
> the URL nominated in STATIC_URL.
>
> In production they need to be all collected and copied into the
> directory root specified in STATIC_ROOT. This relies on the production
> webserver (eg Apache) being configured to serve files in the STATIC_ROOT
> directory at the URL nominated in STATIC_URL.
>
> This collecting should be done via './manage.py collectstatic' just once
> per fresh source deployment and then only if the static files have changed.
>
> Static files settings:
> =====================
> [9]
> # My preferred project path location for static files
> STATICFILES_DIRS = (
>      os.path.join(SRC_ROOT, 'static/').replace('\\','/'),
> )
> if DEBUG:
>      i = 0
>      for item in STATICFILES_DIRS:
>          i += 1
>          print('STATICFILES_DIRS = %s (#%s)' % (item, i ))
>
> [10]
> # I prefer to keep STATIC_ROOT differences here rather than urls.py
> if DEBUG:
>      STATIC_ROOT = os.path.join(PROJECT_ROOT,
> 'htdocs/static/').replace('\\','/')
>      print('STATIC_ROOT      = %s %s' % (STATIC_ROOT, '(collectstatic)'))
> else:
>      # actual staging and production webserver directory
>      STATIC_ROOT = '/srv/www/%s/htdocs/static/' % PROJECT
>
> > Do you ran
> > ./manage.py runserver
>
> > or do you run under a real web server.
>
> > I you run under anything else than ./manage.py runserver, then
>
> > don't forget to run
> > ./magage.py collectstatic

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to