Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.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不';无法仅在远程服务器中找到文件_Python_Django_Linux_Apache - Fatal编程技术网

Python Django不';无法仅在远程服务器中找到文件

Python Django不';无法仅在远程服务器中找到文件,python,django,linux,apache,Python,Django,Linux,Apache,我在Django有一个项目,在那里我有一个读取文件的函数。在我使用virtualenv的本地环境中,它可以读取文件。但是,当我把它放在我们的远程服务器(使用LINUX Ubuntu+Apache2)中时,它表明Python找不到该文件。我做错了什么 utils.py def set_vehicles_negotiations(self): # This method will get all current negotiations that means and set it in th

我在Django有一个项目,在那里我有一个读取文件的函数。在我使用virtualenv的本地环境中,它可以读取文件。但是,当我把它放在我们的远程服务器(使用LINUX Ubuntu+Apache2)中时,它表明Python找不到该文件。我做错了什么

utils.py

def set_vehicles_negotiations(self):
    # This method will get all current negotiations that means and set it in the database
    with open("reports/dash_diversos.csv", 'rt', encoding='utf8') as csvfile: ...
...
def dashboard(request):
     csvReaders = CSVReaders()
     csvReaders.set_vehicles_negotiations()
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static') # This line exist's only in the remote server
视图.py

def set_vehicles_negotiations(self):
    # This method will get all current negotiations that means and set it in the database
    with open("reports/dash_diversos.csv", 'rt', encoding='utf8') as csvfile: ...
...
def dashboard(request):
     csvReaders = CSVReaders()
     csvReaders.set_vehicles_negotiations()
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static') # This line exist's only in the remote server
设置.py

def set_vehicles_negotiations(self):
    # This method will get all current negotiations that means and set it in the database
    with open("reports/dash_diversos.csv", 'rt', encoding='utf8') as csvfile: ...
...
def dashboard(request):
     csvReaders = CSVReaders()
     csvReaders.set_vehicles_negotiations()
...
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static') # This line exist's only in the remote server
目录结构:

mydashboard
- dashboard
-- utils.py
-- views.py
- reports
-- dash_diversos.csv
错误消息:

[Errno 2]没有这样的文件或目录:“reports/dash\u diversos.csv”

apache/sites available/000 default.conf

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin ***
        DocumentRoot /var/www/dashboard

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

        Alias /static /var/www/dashboard/static
        <Directory /var/www/dashboard/static>
                Require all granted
        </Directory>

        Alias /media /var/www/dashboard/media
        <Directory /var/www/dashboard/media>
                Require all granted
        </Directory>

        <Directory /var/www/dashboard/ceodashboard>
                <Files wsgi.py>
                        Require all granted
                </Files>
        </Directory>

    WSGIDaemonProcess dashboard python-home=/var/www/dashboard/dashboardenv python-path=/var/www/dashboard
    WSGIProcessGroup dashboard
    WSGIScriptAlias / /var/www/dashboard/ceodashboard/wsgi.py

</VirtualHost>

#ServerName指令设置请求方案、主机名和端口
#服务器使用来标识自身。这在创建时使用
#重定向URL。在虚拟主机的上下文中,服务器名
#指定必须在请求的主机:标头中显示的主机名
#匹配此虚拟主机。对于默认虚拟主机(此文件),此
#该值不是决定性的,因为它被用作最后的宿主。
#但是,必须为任何其他虚拟主机显式设置它。
#服务器名www.example.com
服务器管理员***
DocumentRoot/var/www/dashboard
#可用日志级别:trace8、…、trace1、调试、信息、通知、警告、,
#错误、暴击、警报、紧急情况。
#还可以为特定应用程序配置日志级别
#模块,例如。
#日志级别信息ssl:警告
ErrorLog${APACHE_LOG_DIR}/error.LOG
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
#对于conf/available/中的大多数配置文件
#在全局级别启用或禁用,可以
#仅包含一个特定虚拟主机的行。例如
#以下行仅为此主机启用CGI配置
#在使用“A2F”全局禁用后。
#包括conf available/service-cgi-bin.conf
别名/static/var/www/dashboard/static
要求所有授权
别名/media/var/www/dashboard/media
要求所有授权
要求所有授权
WSGIDaemonProcess dashboard python home=/var/www/dashboard/dashboardenv python path=/var/www/dashboard
WSGIProcessGroup仪表板
WSGIScriptAlias//var/www/dashboard/ceodboard/wsgi.py

我已经在各种网站上搜索过了。我只是不明白为什么它在我的本地机器上工作,而不是在我的服务器上

需要检查的内容有:(1)文件实际存在;(2)文件具有运行Python的用户可以访问的权限。如果您在
/var/www
下部署应用程序,您可能会发现,除非您正确配置了站点,否则Apache将妨碍您的工作。在检查权限以便Apache组/用户可以访问静态文件之后,您是否也可以提供Apache站点配置?您还可以尝试运行
python manage.py collectstatic
作为故障排除步骤,您可以为它提供一个完整路径,即-->
打开(“/var/www/full/path/to/reports/dash_diversos.csv
@sytech),(1)是的,文件在那里。(2)只是为了确认一下,我输入了777权限,没有任何内容……(3)是的,我在/var/www/dashboard下部署了我的应用程序。我还设置了以下权限:sudo chown:www-data/var/www/dashboard。(4)是的,我做到了:运行collectstatic。但问题仍然存在。@Zak,谢谢。是的,完整路径可以工作。但问题是,在我的本地计算机中,我将有一个路径,当我上传它时,它将被替换,问题将再次出现……这里没有几个选项:(1)您可以调整wsgi配置()要将应用程序设置在正确的工作目录中,以便相对路径能够工作,或者(2)在代码中以跨环境工作的方式形成该路径,可以
file\u path=os.path.join(settings.STATIC\u ROOT,'reports','dash\u diversos.csv')