Django 静态资源路径问题(一)

2013.10.17日(初学,手写) 系统 ubuntu  python2.7.4   Django1.5.4

1.

/hone/yuluhuang/python/

2.创建项目

django-admin.py startprojects  one   ==>   /hone/yuluhuang/python/one/one[产生两个one文件夹]

3.进入

cd one/one

4.创建应用

django-admin.py startapp blog

5.进入blog文件夹 在blog文件夹中创建templates文件夹

cd blog

mkdir templates

    在里面新建index.html

  ...

   <tr><td width="43"><img src="/templates/xxx/xxx.png" alt="" width="43" height="72" /></td></tr>

  ... 

6.括号内为此文件下的文件

/hone/yuluhuang/python/one(manage.py)/one(setting.py,urls.py..)/blog(models.py,views.py)/templates

7.打开setting.py 修改如下

vim setting.py

import os

...

STATIC_URL = '/templates/'

# Additional locations of static files
STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__), './blog/templates/').replace('\\','/'),

# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)

7.1

vim urls.py

         url(r'^index/$','one.blog.views.login'),

7.2

vim views.py

from django.http import HttpResponse
from django.shortcuts import render_to_response

def index(req):
return render_to_response('index.html',{})

8.调用如下

<tr>
<td width="43"><img src="/templates/xxx/xxx.png" alt="" width="43" height="72" /></td>
</tr>

 

 

 

 

posted @ 2013-10-18 09:33  yuluhuang  阅读(918)  评论(0编辑  收藏  举报