Py学习  »  问与答

模板调用js路径问题

rockyaow • 11 年前 • 4481 次点击  

首先看下我的配置

URL配置 url(r'^test_render/(?P<tname>[^/]+)/$', 'pp.views.test_render', name='test_render'),

VIEW

def test_render(request, tname):
    return render_to_response(tname)

模板里面

<script src="/static/js/login.js"></script>

然后访问

http://127.0.0.1:8000/test_render/regist.html/

结果调用的JS地址变为

http://127.0.0.1:8000/test_render/regist.html/static/js/login.js

应该是

http://127.0.0.1:8000/static/js/login.js

这个是为什么啊? 哪里配置错了?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/275
 
4481 次点击  
文章 [ 1 ]  |  最新文章 11 年前
echeng192
Reply   •   1 楼
echeng192    11 年前

setting里有没有设静态文件目录? import os.path STATICFILES_DIRS = ( os.path.join(os.path.dirname(file), '../static').replace('\','/'), )