I have a Django project called myproject
, which has an app called myapp
. I want to read a text file and load its contents into a list. I'm a little confused about static files and relative directories in Django, and my initial attempt is not working. So far, I have the following code...
In /myproject/settings.py
:
STATIC_URL = '/static/'
In /myapp/static/myapp
, there is a file called myfile.txt
.
In /myapp/views.py
:
with open('myapp/myfile.txt') as f:
lines = f.readlines()
When running the server, I get the error: No such file or directory: 'myapp/myfile.txt'
What am I doing wrong?