Saturday, February 5, 2011

Re: Help on adding CSS to django project

It seems that you need to setup your web server to support static contents, django has a middleware to do the job, but it is not recommended to use it in product environment. I had this similar problem when I started to learn django.

On Sat, Feb 5, 2011 at 6:15 AM, Chris Hannam <bassdread@gmail.com> wrote:
Apologies for that premature send:
 
Hi,
The way I have approached this is to have a static dir set in my urls.py:
 
(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT }
         )

settings.py has the following
MEDIA_ROOT = os.path.join(PATH_SITE_ROOT, 'static')
PATH_SITE_ROOT = os.path.normpath(os.path.dirname(__file__))

I reference the css files in the html as /static/css/style.css etc

The urls.py maps the url to the location on disk of the css files.

Can you supply the error messages and some of your config if you are still having issues?

CH

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



--
===========================
Regards
Ronghui Yu

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