Sunday, January 30, 2011

Re: svn django and staticfiles app : python manage.py findstatic logo.png and devserver does not find file

On 30.01.2011, at 20:58, hari jayaram wrote:

> Hi I am a little confused about using the staticfiles app. I am running the devserver since I am learning django and building a site.
>
> I have my logo and css files at
>
> /Users/harijay/learn_css/logo.png
> /Users/harijay/learn_css/my_master.css
>
>
> STATIC_ROOT="/Users/harijay/learn_css/"
> STATIC_URL="/static/"

Quoting the docs:

"This is not a place to store your static files permanently; you should do that in directories that will be found by staticfiles's finders, which by default, are 'static' app sub directories and any directories you include in the STATICFILES_DIRS setting)." -- http://docs.djangoproject.com/en/dev/ref/settings/#static-root

Simply put, STATIC_ROOT is only needed if you want to use the collectstatic management command during deployment. It collects static files from various locations in STATIC_ROOT so you can make that single directory accessible with your web server.

We further describe this here: http://docs.djangoproject.com/en/dev/howto/static-files/

The solution for you should be to add a setting:

STATICFILES_DIRS = (
"/Users/harijay/learn_css/",
)

Jannis


> My Django project directory is
>
> /Users/harijay/learn_django
>
> I am not using anything extra in my urls.py (attached below). in my template I am composing my static links as follows
> t = Template (""".....
> @import url("{{STATIC_URL}}my_master.css");
> <img src="{{STATIC_URL}}logo.png"/>
> """)
>
> And returning the response as follows
> c = RequestContext(request)
> return (HttpResponse(t.render(c)))
>
> My problem is that the logo.png and my_master.css only get served if they are put in the project directory i.e /Users/harijay/learn_django
> They are showed at the URL http://localhost:8000/static/logo.png
>
>
> I am trying to understand what I am doing wrong. I had gotten suggestions on the irc channel to use django_appmedia but I want to go with staticfiles app since it is better documented.
>
> Any Help will be greatly appreciated
>
> Hari
>
>
> ###########
> urls.py
> ###########
>
> from django.conf.urls.defaults import *
> from bscencoder.views import hello
> from bscencoder.views import upload_to_s3_form
> from bscencoder.views import mymain
> import settings
> #from django.contrib.staticfiles.urls import staticfiles_urlpatterns
>
>
> # Uncomment the next two lines to enable the admin:
> # from django.contrib import admin
> # admin.autodiscover()
> # Old method of serving static files with devserv
> #(r'^(?P<path>.*)$', 'django.views.static.serve',{'document_root': '/Users/harijay/learn_css'}),
>
> urlpatterns = patterns('',
> # Example:
> # (r'^bscencoder/', include('bscencoder.foo.urls')),
>
> # Uncomment the admin/doc line below to enable admin documentation:
> # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
>
> # Uncomment the next line to enable the admin:
> # (r'^admin/', include(admin.site.urls)),
> (r'^/?$',mymain),
> (r'^hello/?',hello),
> (r'^upload/?',upload_to_s3_form),
> )
>
> #if settings.DEBUG: # assuming dev server
> # urlpatterns += patterns(r'^(?P<path>.*)$', 'django.views.static.serve',{'document_root': STATIC_ROOT })

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

No comments:

Post a Comment