1

I am new to python.

I want to access a file using path.

My Directory looks like this

main_folder
├───backend
│   └───src
│       ├───apps
│       │   └───frontendreact/views.py
├───frontend
│   └───src
│   └───templates
│       ├───index.html

I have witten in code.


def index(request):
    import os
    print('\n')

    print(os.getcwd()) # This print -->> D:\main_folder\backend\src

    print('\n')
    return render(request, '../../frontend/templates/frontend/index.html')

Above code is giving me error - TemplateDoesNotExist at /

But I want to access the file which is in main_folder/frontend/templates/index.html.

But my python file from where i am calling path is in main_folder/backend/src/apps/frontendreact/views.py.html

1 Answer 1

1

But I want to access the file which is in main_folder/frontend/templates/index.html.

If that's the case you need to change the last line of your code to return render(request, '../../frontend/templates/index.html')

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.