Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 找不到django文件style.css_Python_Css_Django_Django Templates - Fatal编程技术网

Python 找不到django文件style.css

Python 找不到django文件style.css,python,css,django,django-templates,Python,Css,Django,Django Templates,我的css失败了。“我的模板”页面中没有初始化css命令。 django没有显示任何错误,但在apache日志中,我看到stlye.css无法找到,即使是静态路径 [wsgi:error] [pid 25372] [remote 73.135.97.117:47050] Not Found: /home/robin/www/trader/templates/trader/style.css 但是文件就在那里。我尝试了对style.css文件的权限644和777 root@localhost:/

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

[wsgi:error] [pid 25372] [remote 73.135.97.117:47050] Not Found: /home/robin/www/trader/templates/trader/style.css
但是文件就在那里。我尝试了对style.css文件的权限644和777

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
我的apache指令看起来正常

<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

添加URL.py

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

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)
还尝试:

root@localhost:/home/robin/www/trader# python3 manage.py findstatic templates/trader/style.css 
No matching file found for 'templates/trader/style.css'.


root@localhost:/home/robin/www/trader# ls -l templates/trader/style.css
-rw-r----- 1 www-data www-data 155 May 13 12:46 templates/trader/style.css
还尝试:

root@localhost:/home/robin/www/trader# python3 manage.py findstatic templates/trader/style.css 
No matching file found for 'templates/trader/style.css'.


root@localhost:/home/robin/www/trader# ls -l templates/trader/style.css
-rw-r----- 1 www-data www-data 155 May 13 12:46 templates/trader/style.css

chmod 0644和0655用于style.css(在所有目录和静态URL组合中),同样不需要。

提供
STATICFILES\u DIRS
@Lemayzeur既不提供STATIC\u URL='/home/robin/www/trader/templates/trader/'也不提供STATICFILES\u DIRS='/home/robin/www/trader/templates/trader/'worked@Lemayzeur在配置中添加静态文件路径时,我看不到我的html。可能您在apache配置中遗漏了静态文件的别名
Alias/static/home/path/path/static
,并且
STATICFILES\u DIRS
static\u URL
是important@LemayzeurServerAlias/trader/home/robin/www/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)
root@localhost:/home/robin/www/trader# python3 manage.py findstatic templates/trader/style.css 
No matching file found for 'templates/trader/style.css'.


root@localhost:/home/robin/www/trader# ls -l templates/trader/style.css
-rw-r----- 1 www-data www-data 155 May 13 12:46 templates/trader/style.css