当第一次加载索引页面时,它会给出静态文件路径:
[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 :(得分:1)
试试这个:
STATICFILES_DIRS = (
...
os.path.join(os.path.dirname(__file__),'static'),
)
TEMPLATE_DIRS = (
...
os.path.join(os.path.dirname(__file__),'templates'),
)