---
title: "配置静态资源总结"
author: "hjoo"
date: "2011-02-16T09:53:54Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2011-02-16T09:54:21Z"
id: 907488
url: "https://hjoo.iteye.com/blog/907488"
---

**setting.py：**
HERE = os.path.dirname(os.path.abspath(__file__))
MEDIA_ROOT = os.path.join(HERE, 'static/')
MEDIA_URL = '/static/'

**urls.py:**
(r'^static/(.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),

**views.py:**
return render_to_response(template_name, RequestContext(request))

模板里就可以直接使用{{MEDIA_URL}}来引用路径了