无法找到django文件style.css

时间:2018-05-13 18:09:35

标签: python css django django-templates

我的css失败了。没有css命令在我的模板页面初始化。 django没有显示错误,但在apache日志中我发现即使使用静态路径也无法找到stlye.css。

Parse.Or

但文件非常多。我尝试了644和777权限到style.css文件

[wsgi:error] [pid 25372] [remote 73.135.97.117:47050] Not Found: /home/robin/www/trader/templates/trader/style.css

我的apache指令看起来很正常

root@localhost:/home/robin/www/trader# ls -l /home/robin/www/trader/templates/trader
total 12
-rw-r--r-- 1 www-data www-data 2905 May 13 14:26 index.html
-rwxrwxrwx 1 www-data www-data  155 May 13 12:46 style.css

settings.py

<VirtualHost *:80>
        ServerName coinz.com
        ServerAdmin webmaster@coinz.com
        DocumentRoot /home/robin/www/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
        WSGIDaemonProcess trader python-path=/home/robin/www/trader/:/usr/lib/python3/dist-packages/
        WSGIProcessGroup trader
        WSGIScriptAlias / /home/robin/www/trader/trader/wsgi.py

        <Directory /home/robin/www/trader/>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>
</VirtualHost>

如何让django找到我的style.css?

更新: HTML

root@localhost:/home/robin/www/trader# cat trader/settings.py 

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = 'xxx'
DEBUG = True

ALLOWED_HOSTS = ['coinz.com']


# Application definition

INSTALLED_APPS = [
        'trader',
        'buy',
        'sell',
        'manager',
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
]

MIDDLEWARE = [
        'django.middleware.security.SecurityMiddleware',
        'django.contrib.sessions.middleware.SessionMiddleware',
        'django.middleware.common.CommonMiddleware',
        'django.middleware.csrf.CsrfViewMiddleware',
        'django.contrib.auth.middleware.AuthenticationMiddleware',
        'django.contrib.messages.middleware.MessageMiddleware',
        'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'trader.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['/home/robin/www/trader/templates/'],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'trader.wsgi.application'

DATABASES = {
        'default': {
                'ENGINE': 'django.db.backends.mysql',
                'NAME': 'xxx',
                'USER': 'xxx',
                'PASSWORD': 'xxx',
                'HOST': '127.0.0.1',
                'PORT': '',
        }
}    
AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True    

STATIC_URL = '/static/'

并添加到settings.py

<head>
{% load static %}
<link rel="stylesheet" type="text/css" href={% static "style.css" %}>

</head>

添加urls.py

root @ localhost:/ home / robin / www / trader #cat trader / urls.py

STATICFILES_DIRS = [
        os.path.join(BASE_DIR, "static"),
        '/home/robin/www/trader/templates/trader/',
]

也尝试过:

from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
from . import views
from django.conf import settings
from django.conf.urls.static import static
app_name = 'trader'
urlpatterns = [
        path('', views.index, name='index'),
        path('admin/', admin.site.urls),
        url(r'^buy/', include('buy.urls')),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

也尝试过:

chmod 0644和0655 for styles.css(在所有目录和STATIC_URL组合中),相同的nah-dah。

0 个答案:

没有答案