Assuming that you have settings.STATIC_ROOT configured, you can use the
following snippet to handle URL routing for static files with the dev
server:

# urls.py
if settings.DEBUG:
    urlpatterns += patterns('',
        (r'^static/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.STATIC_ROOT,
        }),
    )

Feel free to add a similar pattern for media files as well.

Hope this helps,
Jonathan

On 01/08/2013 04:25 AM, Agnese Camellini wrote:
> I'm not using apache now, i'm just using the development server into
> django.
> Why is it so difficult to serve static files?
> joy
>
> 2013/1/8 Mike Dewhirst <mi...@dewhirst.com.au
> <mailto:mi...@dewhirst.com.au>>
>
>     On 8/01/2013 10:03pm, joy wrote:
>
>         I have the same problem, the tutorial speaks about a list of
>         things to do:
>
>           * Push your code up to the deployment server.
>           * On the server, run collectstatic
>            
>         
> <https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/#django-admin-collectstatic>
>             to copy all the static files into STATIC_ROOT
>            
>         
> <https://docs.djangoproject.com/en/1.4/ref/settings/#std:setting-STATIC_ROOT>.
>           * Point your web server at STATIC_ROOT
>            
>         
> <https://docs.djangoproject.com/en/1.4/ref/settings/#std:setting-STATIC_ROOT>.
>
>         I have arrived at the second point. But the static files are
>         not served,
>         i have set up the STATIC ROOT and the STATIC_URL, but what
>         should i add
>         to the template src tag to find the pages? The tutorial speaks
>         about the
>         template context processor, but it doesn't exist in my
>         setting.py file.
>
>         TEMPLATE_CONTEXT_PROCESSORS  =  (
>              'django.core.context_processors.debug',
>              'django.core.context_processors.i18n',
>              'django.core.context_processors.media',
>              'django.core.context_processors.static',
>              'django.contrib.auth.context_processors.auth',
>              'django.contrib.messages.context_processors.messages',
>         )
>
>         i cannot make my css and javascript work, please, can you
>         explain me what is happening behind the interface?
>         Agnese
>
>
>         Il giorno sabato 5 gennaio 2013 19:38:32 UTC+1, MÄ rtiņš
>         JakuboviÄ s
>         ha scritto:
>
>             Hello.
>
>             I try a lot of things and can't understand, why not working
>             STATIC_ROOT and MEDIA_ROOT in settings.py.
>
>             I want, that all my media and static folders is in
>         different place
>             that python files, so I set media, static and templates to
>         different
>             place. Templates TEMPLATE_DIRS works well, bet MEDIA_ROOT
>             and STATIC_ROOT not.
>
>             I try setup like this:
>
>             /home/domain/www/my_proj/ there is project folder and all
>         apps, and
>             there I place my htdocs folder, in which is static,
>         templates and
>             media folders.
>
>             When i set in STATIC_ROOT =
>         '/home/domain/www/my_proj/htdocs/static'
>
>             In apache error log i got:
>
>             File does not exist: /home/domain/www/my_proj/my_proj/static
>
>             I don't get, why django don't want to take new setting...
>
>             I use django 1.4.
>
>
>     I think you need to set up Apache to serve the static and media
>     files. Here is how mine works ...
>
>      # lock the public out
>      <Directory /var/www/my_proj/>
>       AllowOverride None
>       Order deny,allow
>       Deny from all
>      </Directory>
>
>      # serve uploaded media from here
>      <Directory /var/www/media/my_proj/>
>       AllowOverride None
>       Order deny,allow
>       Allow from all
>      </Directory>
>
>      # serve static stuff from here
>      <Directory /var/www/static/my_proj/>
>       AllowOverride None
>       Order deny,allow
>       Allow from all
>      </Directory>
>
>      <IfModule mod_alias.c>
>       Alias /media/ /var/www/media/my_proj/
>       Alias /static/ /var/www/static/my_proj/
>       Alias /tiny_mce/ /var/www/static/my_proj/js/tiny_mce/
>       Alias /jquery/ /var/www/static/my_proj/js/jquery/
>      </IfModule>
>
>     Then in your template you can use {{ STATIC_URL }}/whatever
>
>     Hope this helps
>
>     Mike
>
>
>             Thanks.
>
>         --
>         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/-/fwNEyOLpFb4J.
>         To post to this group, send email to
>         django-users@googlegroups.com
>         <mailto:django-users@googlegroups.com>.
>         To unsubscribe from this group, send email to
>         django-users+unsubscr...@googlegroups.com
>         <mailto: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
>     <mailto:django-users@googlegroups.com>.
>     To unsubscribe from this group, send email to
>     django-users+unsubscr...@googlegroups.com
>     <mailto: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 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 at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to