Not able to find static file path page redirect to another page

偶尔善良 提交于 2019-12-24 16:31:06

问题


When first time index page load it give static file path:

[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 

After click on hyperlink it redirect to another page static file path change to:

[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

After redirect to another page it's not able to find the static file path.

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)),
)

回答1:


Try this:

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

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


来源:https://stackoverflow.com/questions/30028298/not-able-to-find-static-file-path-page-redirect-to-another-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!