Re: Confusion about the new staticfiles contrib app
On Tue, 25 Jan 2011 21:46:39 -0800 (PST) Brian Neal wrote: Hiya, > I'm trying to cut over my project to use the new staticfiles > application. I'm using the dev server with DEBUG = True on a recent > SVN trunk checkout. My STATIC_URL is '/static/' and my MEDIA_URL is > 'http://localhost:8000/media/' in this environment. I'm in a similar boat...trying (again) with Django-1.3 > Eventually I came to the conclusion that I had do this: > > urls.py: > if settings.DEBUG: >urlpatterns += patterns('django.contrib.staticfiles.views', > (r'^media/(?P.*)$', 'serve', {'document_root': > settings.MEDIA_ROOT}), >) My project is at ~/home/gour/www/zinnia in virtual env. Zinnia (blog engine) media files are symlinked to: /usr/home/gour/www/zinnia/lib/python2.7/site-packages/zinnia/media/zinnia --> /usr/home/gour/www/zinnia/blog/static and in order to see media files I've the following in my settings.py: [...] PROJECT_PATH = os.path.abspath(os.path.dirname(__file__)) MEDIA_ROOT = os.path.join(PROJECT_PATH, "static") MEDIA_URL = '/media/' ADMIN_MEDIA_PREFIX = '/media/admin/' [...] and here is the snippet from urls.py: from django.conf import settings if settings.DEBUG: urlpatterns += patterns('', url(r'^media/(?P.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT, }), ) The above snippet is from dev-docs, while the 1.3 doc says: from django.conf import settings if settings.DEBUG: urlpatterns += patterns('django.contrib.staticfiles.views', url(r'^static/(?P.*)$', 'serve'), ) Now I'm told on #django that this is obsolete and from 1.3 one is supposed to use: django.contrib.staticfiles and I tried to add it to INSTALLED_APPS, defined STATIC_ROOT, STATIC_URL, STATICFILES_DIRS..and adding: urlpatterns += staticfiles_urlpatterns() to urls.py, but all what I get is 404 errors. > The docs don't seem to mention using this view for this purpose. > Should they? This is my confusion as well. The doc says: This view is automatically enabled by runserver (with a DEBUG setting set to True). To use the view with a different local development server, add the following snippet to the end of your primary URL configuration: from django.conf import settings if settings.DEBUG: urlpatterns += patterns('django.contrib.staticfiles.views', url(r'^static/(?P.*)$', 'serve'), ) and based on the avove it seems that if one just wants to use runserver there should not be need for the django.contrib.staticfiles.views view, but, based on my experience I was not able to render media files without using the above snippet in urls.py, so my humgble request is whether someone can provide correct info how to serve app's media (static) files in django-1.3 when using runserver in development? Sincerely, Gour -- “In the material world, conceptions of good and bad are all mental speculations…” (Sri Caitanya Mahaprabhu) http://atmarama.net | Hlapicina (Croatia) | GPG: 52B5C810 signature.asc Description: PGP signature
Re: Confusion about the new staticfiles contrib app
I can answer one of my own questions now: On Jan 25, 11:46 pm, Brian Neal wrote: ... > My second confusion point: > I am running the dev server with -Wall and I am seeing warnings: > PendingDeprecationWarning: The view at `django.views.static.serve` is > deprecated; use the path `django.contrib.staticfiles.views.serve` > instead. > > I don't understand why I'm getting these warnings. This warning is being generated by the django debug toolbar calling into the deprecated view function. -BN -- 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.
Re: Confusion about the new staticfiles contrib app
On Jan 26, 8:46 am, Jonas Geiregat wrote: > > MEDIA_ROOT is the path to the directory where your files will live. > > MEDIA_URL is the URL the get to those files. > > So if MEDIA_ROOT='/home/you/media' > and MEDIA_URL='site-media/' > > Then if you want to view a file located at /home/you/media/thisFile.jpg you > enterhttp://yoursite.com/site-media/thisFile.jpg. I understand the settings just fine. Are you saying that the dev server is serving your media files? Because it isn't for me. It is only serving the static media. > The same counts for STATIC_ROOT and STATIC_URL. What do you have STATIC_URL set to? Is it different than your MEDIA_URL? Thanks. -- 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.
Re: Confusion about the new staticfiles contrib app
>> > > I don't understand this. One is a URL, the other is a file path. Why > would I set STATIC_URL = MEDIA_ROOT? Or did you make a typo and mean > MEDIA_URL? That might make more sense to me. MEDIA_ROOT is the path to the directory where your files will live. MEDIA_URL is the URL the get to those files. So if MEDIA_ROOT='/home/you/media' and MEDIA_URL='site-media/' Attention never use MEDIA_URL='media/' because that url is already used by the admin interface. Then if you want to view a file located at /home/you/media/thisFile.jpg you enter http://yoursite.com/site-media/thisFile.jpg. The same counts for STATIC_ROOT and STATIC_URL. I hope everything is clear now. I'm aware the docs are pretty much useless on these subjects. But then again that's about the only thing you can say bad about django's documentation. Sorry if I wasn't that obvious this morning but I didn't sleep well and I had little time. But I could feel your frustration since I had the same problem going on some day's ago. Good luck! -- 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.
Re: Confusion about the new staticfiles contrib app
On Jan 26, 1:46 am, Jonas Geiregat wrote: > Op 26-jan-2011, om 06:46 heeft Brian Neal het volgende geschreven: > > > Hi - > > I'm trying to cut over my project to use the new staticfiles > > application. I'm using the dev server with DEBUG = True on a recent > > SVN trunk checkout. My STATIC_URL is '/static/' and my MEDIA_URL is > > 'http://localhost:8000/media/'in this environment. > > STATIC_URL and MEDIA_URL are two different things. Agree. > > if you want to serve static files that are related to your > webdesign/development you should use STATIC. > User related files such as uploaded files such be placed inside the MEDIA > path. That is what I'm trying to do. > > so change STATIC_URL into MEDIA_ROOT='static/'. I don't understand this. One is a URL, the other is a file path. Why would I set STATIC_URL = MEDIA_ROOT? Or did you make a typo and mean MEDIA_URL? That might make more sense to me. My question is, if I want to serve my apps' static files at the URL / static/ and user-uploaded media at /media/ (Is this an unusual requirement? Maybe this is typically only done in production?) what is the best way to do this with the dev server, and should the docs be strengthened to support this? The dev server, with DEBUG=True, does a good job of serving my apps' static files at the URL rooted at / static/, but it (obviously) 404's when a request is made for /media/. So here I think I need to configure the new static serving view with the URL pattern /media/ (and point it at my MEDIA_ROOT as I showed in my original post). Or, do most people (in dev. mode) set MEDIA_URL = STATIC_URL, and then add the MEDIA_ROOT path to the STATICFILES_DIRS setting? Or do something else? Could some people could post their full (STATIC|MEDIA)_(ROOT|URL) and STATICFILES_* settings for their dev server environment? I guess I am looking for some "best practice" examples; for some reason this is really tripping me up. Thank you. -- 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.
Re: Confusion about the new staticfiles contrib app
Op 26-jan-2011, om 06:46 heeft Brian Neal het volgende geschreven: > Hi - > I'm trying to cut over my project to use the new staticfiles > application. I'm using the dev server with DEBUG = True on a recent > SVN trunk checkout. My STATIC_URL is '/static/' and my MEDIA_URL is > 'http://localhost:8000/media/' in this environment. STATIC_URL and MEDIA_URL are two different things. if you want to serve static files that are related to your webdesign/development you should use STATIC. User related files such as uploaded files such be placed inside the MEDIA path. so change STATIC_URL into MEDIA_ROOT='static/'. I always use a fullpath when defining a MEDIA_ROOT or STATIC_ROOT. > > My first confusion point: > Maybe it was just me, but I got confused about serving my media > (MEDIA_ROOT/MEDIA_URL) files with the dev server. After cutting over > to staticfiles, my MEDIA_URL files started getting 404s. Eventually I > came to the conclusion that I had do this: > > urls.py: > if settings.DEBUG: > urlpatterns += patterns('django.contrib.staticfiles.views', > (r'^media/(?P.*)$', 'serve', {'document_root': > settings.MEDIA_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.
Confusion about the new staticfiles contrib app
Hi - I'm trying to cut over my project to use the new staticfiles application. I'm using the dev server with DEBUG = True on a recent SVN trunk checkout. My STATIC_URL is '/static/' and my MEDIA_URL is 'http://localhost:8000/media/' in this environment. My first confusion point: Maybe it was just me, but I got confused about serving my media (MEDIA_ROOT/MEDIA_URL) files with the dev server. After cutting over to staticfiles, my MEDIA_URL files started getting 404s. Eventually I came to the conclusion that I had do this: urls.py: if settings.DEBUG: urlpatterns += patterns('django.contrib.staticfiles.views', (r'^media/(?P.*)$', 'serve', {'document_root': settings.MEDIA_ROOT}), ) The docs don't seem to mention using this view for this purpose. Should they? My second confusion point: I am running the dev server with -Wall and I am seeing warnings: PendingDeprecationWarning: The view at `django.views.static.serve` is deprecated; use the path `django.contrib.staticfiles.views.serve` instead. I don't understand why I'm getting these warnings. My code no longer references django.views.static.serve. I even see this warning when looking at an admin page. Any thoughts on why this is occurring? Thanks. PS After coming to terms with staticfiles, I think it is a great idea. I like being able to separate my apps' static files from user uploaded media files. -- 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.