views:

715

answers:

2

I am using django 0.96 for the appengine project. I wanted to use javascript and css in my html files unfortunately i am unable to do it via django... One solution(which i don't like) is to make my app.yaml something like this:

handlers:
- url: /media
  static_dir: static/media

But i want it to do with django itself so i avoided using the above line and hence am seeking a "django" way of doing it. The directory structure of my project is like(not complete just the relevants project /myapp /static /media /css /js /images settings.py app.yaml

and a sample template file header is:

<link type="text/css" href="/media/css/ui-lightness/jquery-ui-1.7.1.custom.css" rel="Stylesheet" /> 
<script type="text/javascript" src="/media/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/media/js/jquery-ui-1.7.1.custom.min.js">$('#date').datepicker();</script>

the settings.py has:

MEDIA_ROOT =  os.path.join(os.path.dirname(__file__), 'static')
MEDIA_URL ='/media/'
TEMPLATE_DIRS = (

    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    os.path.join(os.path.dirname(__file__), 'myapp/templates'),
    os.path.join(os.path.dirname(__file__), 'static'),
)

I know i am making a mistake in the headers or setting because when i use absolute url like:

then atleast the css works. The solution exists to do it with app.yaml(as i mentioned above) but i wanted to do it from django itself. Any hints? Thanks

+1  A: 

I don't know much about GAE, but I do know Django, and the Django way of doing it is not to let Django do it. Your static assets should always be served separately from Django, otherwise you're incurring massive processor overhead for no reason at all.

The way you've got it set up using the handlers above looks like the right way.

Daniel Roseman
http://www.djangoproject.com/documentation/0.96/static_files/ i found this...Seems you were right. thanks
Dhushyanth
+1. Static handlers in App Engine are faster than anything you can implement in user code, too.
Nick Johnson
A: 

Check out the documentation for Google App Engine here:

Static File Handlers Outside of django is the best way to serve static files, and GAE automatically handles mime types.

Mike Johnson