Django 静态资源路径问题(一)
2013.10.17日(初學(xué),手寫(xiě)) 系統(tǒng) ubuntu ?python2.7.4 ? Django1.5.4
1.
/hone/yuluhuang/python/
2.創(chuàng)建項(xiàng)目
django-admin.py startprojects ?one ? ==> ??/hone/yuluhuang/python/one/one[產(chǎn)生兩個(gè)one文件夾]
3.進(jìn)入
cd one/one
4.創(chuàng)建應(yīng)用
django-admin.py startapp blog
5.進(jìn)入blog文件夾 在blog文件夾中創(chuàng)建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.括號(hào)內(nèi)為此文件下的文件
/hone/yuluhuang/python/one(manage.py)/one(setting.py,urls.py..)/blog(models.py,views.py)/templates
7.打開(kāi)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.調(diào)用如下
<tr>
<td width="43"><img src="/templates/xxx/xxx.png" alt="" width="43" height="72" /></td>
</tr>
?
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/yuluhuang/p/3375444.html
總結(jié)
以上是生活随笔為你收集整理的Django 静态资源路径问题(一)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: bit byte B KB Kb
- 下一篇: NuGet学习笔记(1)——初识NuGe