简体   繁体   English

如何在django项目中添加文件路径

[英]how to add file path in django project

I am making an online judge in Django.我正在 Django 中做在线评委。 I am taking user code in a file and then compile it and running it and giving the verdict.我将用户代码放入文件中,然后编译并运行它并给出判断。 for example let say a user submitted code in c++ language so I am taking that code in a .cpp file and compile it and running it and I am doing it by giving the absolute path of my .cpp file like E:\online_judge_project\oj\language\forcpp.cpp例如,假设用户使用 c++ 语言提交了代码,所以我将该代码放在 .cpp 文件中并编译并运行它,我通过提供我的 .cpp 文件的绝对路径来做到这一点,例如 E:\online_judge_project\oj \语言\forcpp.cpp

my problem is that when I will deploy my project it will cause error because this paths are my local machine path and I can't use that in deployment so how will I access the files( like .cpp file) after the deployment.我的问题是,当我部署我的项目时,它会导致错误,因为这个路径是我的本地机器路径,我不能在部署中使用它,所以我将如何在部署后访问文件(如 .cpp 文件)。 Although those files are in my project directory only and I kept them in a folder name language .尽管这些文件仅在我的项目目录中,并且我将它们保存在文件夹名称language 中 my project directory structure is like:我的项目目录结构如下:

在此处输入图像描述

I am thinking of using os.join.path() but I am not getting how to do that.我正在考虑使用os.join.path()但我不知道如何做到这一点。

did you consider putting your cpp file inside static files and define STATIC_URL and STATICFILES_DIRS in your setting.py您是否考虑将您的 cpp 文件放在静态文件中并在您的 setting.py 中定义 STATIC_URL 和 STATICFILES_DIRS

you can put in the function you are using cpp file你可以把你正在使用的函数 cpp 文件

import os
print(os.getcwd())

this script to know exact location of your script and put cpp file in the same path then you should can access it这个脚本知道你的脚本的确切位置并将cpp文件放在同一路径中,那么你应该可以访问它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM