Struggling with static files

36 views
Skip to first unread message

DJ-Tom

unread,
Oct 22, 2012, 4:56:20 AM10/22/12
to django...@googlegroups.com
Hi,

I'm fairly new with Django and currently I'm only "playing around" to get a better feeling for the framework.

I have read the documentation and almost all of the posts here about configuring static files with the development server but can't get it working.

I wanted to modify the admin login screen to show a company logo, so I copied base_site.html to /templates/admin/ and added this:

   <img src="{{ STATIC_URL }}logo.gif" />


This is how my directory structure looks like:

el_test
  el_test
    static
       logo.gif
    settings.py
    urls.py
  templates
    admin
      base_site.html

- Settings.py:

STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

I also added the following to urls.py

   urlpatterns += staticfiles_urlpatterns()

The HTML in the admin logon screen looks like this, so basically the URL seems to be OK

<div id="branding">
  <img src="/static/logo.gif">
  <h1 id="site-name">Test Admin</h1>
</div>


Calling http://localhost:8000/static/logo.gif directly shows a 404 error.

As far as I have understood this should work with the dev server and debug=true without calling collectstatic

I have also tried moving the /static/ folder around various locations below the project directory...

I'm sure there is only some small thing missing...

Any help is highly appreciated :-)

Thomas

Pervez Mulla

unread,
Oct 22, 2012, 5:10:36 AM10/22/12
to django...@googlegroups.com
Give path to your STATIC_ROOT of your static folder.


Pervez


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/YqVkguDtVwEJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Xavier Ordoquy

unread,
Oct 22, 2012, 5:18:04 AM10/22/12
to django...@googlegroups.com
Hi,

Your static folder should be declared in STATICFILES_DIRS if you want him to be served (see https://docs.djangoproject.com/en/1.4/howto/static-files/#basic-usage about that).

Please take care to give another name to STATIC_ROOT for production settings.

Regards,
Xavier Ordoquy,
Linovia.


Pervez Mulla

unread,
Oct 22, 2012, 5:25:39 AM10/22/12
to django...@googlegroups.com
something like this in your setting.py

STATIC_ROOT = ''/home/john/yourprojectdir/yourappdir/staic/"

Xavier Ordoquy

unread,
Oct 22, 2012, 5:32:50 AM10/22/12
to django...@googlegroups.com

Le 22 oct. 2012 à 11:25, Pervez Mulla <mulla...@gmail.com> a écrit :

something like this in your setting.py

STATIC_ROOT = ''/home/john/yourprojectdir/yourappdir/staic/"

This is precisely what you shouldn't do.
The STATIC_ROOT is where files are copied to for production using the collectstatic command.
This is not for development and this is not where you should store your project's static files.

Regards,
Xavier Ordoquy,
Linovia.

DJ-Tom

unread,
Oct 22, 2012, 6:06:44 AM10/22/12
to django...@googlegroups.com


Am Montag, 22. Oktober 2012 11:19:42 UTC+2 schrieb Xavier Ordoquy:
Hi,

Your static folder should be declared in STATICFILES_DIRS if you want him to be served (see https://docs.djangoproject.com/en/1.4/howto/static-files/#basic-usage about that).

 

All the documentation refers to  STATICFILES_DIRS as "this is where tu put additional paths" with INSTALLED_APPS/static being the default path.

If I add this to STATICFILES_DIR:

      '/el_test/static'

...the admin page login completely loses any styling because it can't serve the admin css files anymore
(the url's are http://localhost:8000/static/admin/css/login.css and http://localhost:8000/static/admin/css/base.css)

So either the documentation is wrong or I understand the word "additional" in a different way as the author of the documentation...

DJ-Tom

unread,
Oct 22, 2012, 6:38:25 AM10/22/12
to django...@googlegroups.com


Am Montag, 22. Oktober 2012 12:06:44 UTC+2 schrieb DJ-Tom:
If I add this to STATICFILES_DIR:

      '/el_test/static'


AHHHHHHH - I was missing the trailing comma after the path name... so STATICFILES_DIR was not a valid list.

Everthing's fine now.

Thanks anyways :-)
Thomas
Reply all
Reply to author
Forward
0 new messages