Apache上的FileNotFoundError Django(文件上传)

时间:2018-02-16 13:23:59

标签: django apache upload media

我尝试在我的开发服务器上传文件,但无法使其正常运行。一世 继续得到:

FileNotFoundError at /select_text
[Errno 2] No such file or directory: '/home/metis/public_html/AGATA\\media\\dados_petroleo.txt'
Request Method: POST
Request URL:    http://agata.pgie.ufrgs.br/select_text
Django Version: 2.0.1
Exception Type: FileNotFoundError
Exception Value:    
[Errno 2] No such file or directory: '/home/metis/public_html/AGATA\\media\\dados_petroleo.txt'
Exception Location: /home/metis/public_html/AGATA/textMining/TextMining.py in separete_file_sentences, line 30
Python Executable:  /usr/bin/python3
Python Version: 3.4.3
Python Path:    
['/home/metis/public_html/AGATA',
 '/home/metis/public_html/AGATA/agataenv/lib/python3.4',
 '/home/metis/public_html/AGATA/agataenv/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/metis/public_html/AGATA/agataenv/lib/python3.4/lib-dynload',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/metis/public_html/AGATA/agataenv/lib/python3.4/site-packages']
Server time:    Fri, 16 Feb 2018 13:19:48 +0000

也许它在/home/metis/public_html/AGATA\\media\\dados_petroleo.txt'上,应该是/home/metis/public_html/AGATA/media/dados_petroleo.txt,但它使用的是\\ ......发生了什么?

settings.py:

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

STATIC_URL = '/static/' # You may find this is already defined as such.

STATIC_ROOT = '/home/metis/public_html/static'

STATICFILES_DIRS = (
    STATIC_PATH,
)

MEDIA_ROOT = '/home/metis/public_html/media'

MEDIA_URL = '/media/'

1 个答案:

答案 0 :(得分:2)

您是否可以提供代码的最小工作示例以重现您的问题?

你如何从你的路线获得/传递你的论点?

这看起来有一些逃避现象。

首先(可能不是最好的)想法是在"\\"函数中使用"/"替换separete_file_sentences,然后再使用它。

这将是一个快速修复而不是真正的解决方案TBH。