Home > Blockchain >  how to add file path in django project
how to add file path in django project

Time:07-18

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:

enter image description here

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

CodePudding user response:

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

  • Related