Django没有将STATIC_URL添加到文件路径

时间:2015-09-27 01:17:58

标签: django

无论出于何种原因,Django都没有添加' / static /'我告诉它的网址。

模板:

{% load staticfiles %}
<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="http://getbootstrap.com/favicon.ico">

    <title>Static Top Navbar Example for Bootstrap</title>

    <!-- Bootstrap core CSS -->
        <!-- <img src="{% static "my_app/myexample.jpg" %}" alt="My image"/> -->
        <link href="{% static '/css/bootstrap.min.css' %}" rel="stylesheet">

    <!-- Custom styles for this template -->
        <link href="{% static '/css/navbar-static-top.css' %}" rel="stylesheet">
....

Firefox和Chrome中的HTML输出:

<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="http://getbootstrap.com/favicon.ico">

    <title>Static Top Navbar Example for Bootstrap</title>

    <!-- Bootstrap core CSS -->
        <!-- <img src="/static/my_app/myexample.jpg" alt="My image"/> -->
        <link href="/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
        <link href="/css/navbar-static-top.css" rel="stylesheet">
....

以下是我的设置:

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), 'server_files', 'static')

我尝试删除静态根目录的内容并调用“collectstatic”#39;但无济于事。任何人都知道问题可能是什么,或者我应该做些什么来尝试调试它?

0 个答案:

没有答案