欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

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

发布时间:2025/5/22 31 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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>

 

 

 

 

转载于:https://www.cnblogs.com/yuluhuang/p/3375444.html

总结

以上是生活随笔为你收集整理的Django 静态资源路径问题(一)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。