0

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
  • stackoverflow distorted my directory structure. let me type that again: 1. Project i.myapp ii. settings.py iii. app.yaml iv.static * media ^css ^js Commented Jun 18, 2009 at 6:30

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

djangoproject.com/documentation/0.96/static_files i found this...Seems you were right. thanks
+1. Static handlers in App Engine are faster than anything you can implement in user code, too.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.