Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » svn django and staticfiles app : python manage.py findstatic logo.png and devserver does not find file [RSS Feed]

#1 Jan. 30, 2011 19:58:36

hari j.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


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/"


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 URLhttp://localhost:8000/static/logo.pngI 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+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 30, 2011 20:47:58

Jannis L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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-rootSimply 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 URLhttp://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+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 30, 2011 21:55:18

hari j.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


Thanks for your reply Janice..I am hopefully edging towards understading the
docs

I added the directory to the STATICFILES_DIRS. But the devserver still gives
a 404 on the files which are only in the "/Users/harijay/learn_css"
directory


Also

"python manage.py findstatic logo.png " for example does not find that file


The docs as I understand it implies that in the newest development version,
no special directive in urls.py is required to serve up the static files.
What should STATIC_ROOT and STATIC_URL under those circumstances so that
staticfiles app gets the files "/Users/harijay/learn_css"

Hari






On Sun, Jan 30, 2011 at 3:47 PM, Jannis Leidel <lei...@gmail.com> wrote:

> 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 URLhttp://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+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>

--
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+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Jan. 30, 2011 22:04:12

hari j.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


This may be related to the problem I am facing. The docs mention a
special command to start the devserver to serve static files.


django-admin.py staticfiles-runserver

"
i$ /Users/harijay/djtrunk/django/bin/django-admin.py staticfiles-runserver
Unknown command: 'staticfiles-runserver'
Type 'django-admin.py help' for usage.

"

I am still starting my devserver with

python manage.py runserver

Hari



Hari



On Sun, Jan 30, 2011 at 4:55 PM, hari jayaram <hari...@gmail.com> wrote:
>
> Thanks for your reply Janice..I am hopefully edging towards understading the
> docs
> I added the directory to the STATICFILES_DIRS. But the devserver still gives
> a 404 on the files which are only in the "/Users/harijay/learn_css"  directory
>
> Also
> "python manage.py findstatic logo.png " for example does not find that file
>
> The docs as I understand it implies that in the newest development version,
> no special directive in urls.py is required to serve up the static files.  
> What should STATIC_ROOT and STATIC_URL under those circumstances so that  
> staticfiles app gets the files "/Users/harijay/learn_css"
> Hari
>
>
>
>
>
> On Sun, Jan 30, 2011 at 3:47 PM, Jannis Leidel <lei...@gmail.com> wrote:
>>
>> 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 URLhttp://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+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>>http://groups.google.com/group/django-users?hl=en.
>>
>

--
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+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Jan. 31, 2011 04:50:02

hari j.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


I Solved the problem with help from jezdez on irc and Jannice L on
this newsgroup.

I learned that STATIC_ROOT is the directory where all the static files
will live in when the site is hosted via nginx , apache or a
production webserver.

Following development , the static files are gathered from the various
directories listed in STATICFILES_DIRS and then prepared for hosting
from STATIC_ROOT.

Importantly for my case . I had to add the location of my static file
source directory to the STATICFILE_DIRS tuple in settings.py. I had to
also not add the STATIC_ROOT directory to that list. The two should
not be mixed up .

Importantly also , I got bitten by the trailing slash in my template.
To serve up the static files, my templates just said
{{STATIC_URL}}logo.png . Instead of {{STATIC_URL}}/logo.png - i.e NO
SLASH after
the {{STATIC_URL}}

So I now have staticfiles served up without any extra pattern in my urls.py.

Thanks everyone
Hari



On Sun, Jan 30, 2011 at 5:04 PM, hari jayaram <hari...@gmail.com> wrote:
> This may be related to the problem I am facing. The docs mention a
> special command to start the devserver to serve static files.
>
>
> django-admin.py staticfiles-runserver
>
> "
> i$  /Users/harijay/djtrunk/django/bin/django-admin.py staticfiles-runserver
> Unknown command: 'staticfiles-runserver'
> Type 'django-admin.py help' for usage.
>
> "
>
> I am still starting my devserver with
>
> python manage.py runserver
>
> Hari
>
>
>
> Hari
>
>
>
> On Sun, Jan 30, 2011 at 4:55 PM, hari jayaram <hari...@gmail.com> wrote:
>>
>> Thanks for your reply Janice..I am hopefully edging towards understading the
>> docs
>> I added the directory to the STATICFILES_DIRS. But the devserver still gives
>> a 404 on the files which are only in the "/Users/harijay/learn_css"  
>> directory
>>
>> Also
>> "python manage.py findstatic logo.png " for example does not find that file
>>
>> The docs as I understand it implies that in the newest development version,
>> no special directive in urls.py is required to serve up the static files.  
>> What should STATIC_ROOT and STATIC_URL under those circumstances so that  
>> staticfiles app gets the files "/Users/harijay/learn_css"
>> Hari
>>
>>
>>
>>
>>
>> On Sun, Jan 30, 2011 at 3:47 PM, Jannis Leidel <lei...@gmail.com> wrote:
>>>
>>> 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 URLhttp://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+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>>http://groups.google.com/group/django-users?hl=en.
>>>
>>
>

--
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+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » svn django and staticfiles app : python manage.py findstatic logo.png and devserver does not find file [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support