2015-05-04 46 views
1

当第一次索引页加载给静态文件路径:不能找到静态文件路径页面重定向到另一个页面

[04/May/2015 09:16:22] "GET/HTTP/1.1" 200 3536 
[04/May/2015 09:16:22] "GET /static/css/bootstrap.min.css HTTP/1.1" 304 0 
[04/May/2015 09:16:22] "GET /static/js/jquery.js HTTP/1.1" 304 0 
[04/May/2015 09:16:22] "GET /static/js/bootstrap.min.js HTTP/1.1" 304 0 
[04/May/2015 09:16:22] "GET /static/css/simple-sidebar.css HTTP/1.1" 304 

点击超级链接后,它重定向到另一个页面静态文件路径更改为:

[04/May/2015 10:24:11] "GET /parselog/static/css/simple-sidebar.css HTTP/1.1" 404 2281 
[04/May/2015 10:24:11] "GET /parselog/static/js/jquery.js HTTP/1.1" 404 2251 
[04/May/2015 10:24:11] "GET /parselog/static/css/bootstrap.min.css HTTP/1.1" 404 2278 
[04/May/2015 10:24:11] "GET /parselog/static/js/bootstrap.min.js HTTP/1.1" 404 2272 

重定向到另一页后,它无法找到静态文件路径。

settings.py

STATIC_URL = '/static/' 


STATICFILES_DIRS = (
    # 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. 
    os.path.join(os.path.dirname(__file__),'../static'), 
) 

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 
    # Always use forward slashes, even on Windows. 
    # Don't forget to use absolute paths, not relative paths. 
    os.path.join(os.path.dirname(__file__),'../templates'), 
) 

index.html

<!DOCTYPE html> 
<html lang="en"> 
<head> 
</head> 
<body> 
<div class="row"> 
<div class="col-xs-6 col-sm-4" style='overflow:auto; width:400px; height:500px;'> 
{% for logfile in logfiles %} 
<a href="{% url 'parselog' logfile %}">{{ logfile }}</a> 
<br> 
{% endfor %} 
</div> 
</div> 
</body> 
</html> 

urls.py

from django.conf.urls import patterns, include, url 

from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
    # Examples: 

    url(r'^$', 'fuzeLogApp.views.home', name='home'), 
    url(r'^parselog/(?P<logfile>[\w.-]+)/$', 'fuzeLogApp.views.parselog', name='parselog'), 


    url(r'^admin/', include(admin.site.urls)), 
) 
+0

你能告诉我们你的parselog模板吗?另外你如何添加静态文件到你的index.html? – thegreenogre

回答

1

试试这个:

STATICFILES_DIRS = (
    ... 
    os.path.join(os.path.dirname(__file__),'static'), 
) 

TEMPLATE_DIRS = (
    ... 
    os.path.join(os.path.dirname(__file__),'templates'), 
) 
+0

嘿,非常感谢,它工作得很好。 :) –

相关问题