简体   繁体   中英

how to add file path in django project

I am making an online judge in 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

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. Although those files are in my project directory only and I kept them in a folder name language . my project directory structure is like:

在此处输入图像描述

I am thinking of using os.join.path() but I am not getting how to do that.

did you consider putting your cpp file inside static files and define STATIC_URL and STATICFILES_DIRS in your setting.py

you can put in the function you are using cpp file

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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