Hi Bruno,

Nice tips you got.
thanks :)

-djibon-

On 10/15/09, bruno desthuilliers <bruno.desthuilli...@gmail.com> wrote:
>
> On 14 oct, 19:34, David <baer.da...@gmail.com> wrote:
>> Thanks JIm, didn't solve my problem, but always good to learn some
>> best practices. Any particular reason  why
>> {'document_root' : os.path.join(settings.CURRENT_PATH,"media_site") })
>> is better than
>> {'document_root': settings.MEDIA_ROOT}
>> in settings.py?
>
> Obviously none, except a failure to spot this repetition, I'd say !-)
>
> Here's what we usually do here for dev settings - as DRY as possible:
>
> ## ---- settings.py ----
> import os
>
> # typical default dev server setting
> DEV_SERVER=True
> PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
> PROJECT_URL = 'http://127.0.0.1:8000'
>
> # easier to use the same componant for URL and PATH
> MEDIA_DIR = "site_media"
>
> # the MEDIA_ROOT must end with a path separator AFAICT
> MEDIA_ROOT = os.path.join(PROJECT_PATH, MEDIA_DIR) + os.path.sep
>
> # use the fully qualified URL
> # NB : we don't use os.path.join here - it's an url, not a system path
> MEDIA_URL = "%s/%s/" % (PROJECT_URL, MEDIA_DIR)
>
> # don't forget the media processor for {{ MEDIA_URL }} in the
> templates
> TEMPLATE_CONTEXT_PROCESSORS = (
>     # ....
>     "django.core.context_processors.media",
>     # ....
>     )
>
>
> ## ---- urls.py ----
> from django.conf.urls.defaults import *
> from django.conf import settings
>
> urlpatterns = patterns(
>     '',
>     # urls here
>     )
>
> if settings.get("DEV_SERVER", False):
>     urlpatterns += patterns(
>         '',
>         # static stuff
>         (r'^%s/(?P<path>.*)$' % settings.MEDIA_DIR,
>          'django.views.static.serve',
>          {'document_root': settings.MEDIA_ROOT}
>         ),
>       )
>
>
> ## ---- base.html ----
> <html>
>   <head>
>     <meta http-equiv="Content-Type" content="text/html; charset=utf8" /
>>
>
>     <title>{% block title %}My project's title{% endblock %}</title>
>
>     <link rel="shortcut icon" type="image/ico" href="{{ MEDIA_URL }}
> favicon.ico" />
>     <link rel="stylesheet" type="text/css" href="{{ MEDIA_URL }}
> styles.css" />
>   </head
> <body>
>  <p>etc....</p>
> </body>
> </html>
>
>
> This WorksForUs(tm) so far - as long as the dev server's user has read
> access on MEDIA_ROOT and it's content of course !-)
>
> HTH
>
> >
>


-- 
--------------------------------------------------------------
http://www.tumbletooth.org
my linkedin profile : http://www.linkedin.com/in/bayuadji
--------------------------------------------------------------

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to