views:

37

answers:

1

Hello,

I'm new to web development using python. I've good amount of experience in building dynamic websites using PHP. Also, I've never used MVC on PHP. For the first time I'm using MVC (or MTV to be more correct). I'm following

One thing different from PHP world is that. URLs doesn't point to files but to functions. This single point has made my experience in web development to zero. Its good for HTML content which can be generated from template.

But what about things that shouldn't be rendered like movies, images, pdfs, *.exes, stylesheets & javascript files. I mean for code like this:

<img src="image.jpg" />
or
<link rel="stylesheet" href="stylesheets/style.css" />
or
<a href="/downloads/huge_executable.exe" />

Do I need to write views for these too? If you say just one view like 'getNonRenderingContent' which reads the file and writes to http response with appropriate mime-type.

I feel its stupid & unnecessary load on the server. why should it run code for every such download. Is there any way to directly point urls to files instead of views?

+3  A: 

You can configure your HTTP server to serve your files directly.

You can read about static files in Django here: http://docs.djangoproject.com/en/dev/howto/static-files/

Tomasz Wysocki
also if you have the media context processor added in your context processors (default is so) you can access your MEDIA_URL in your template using {{ MEDIA_URL }} REF: http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-media
patrick