0

I need to pass the route of my index.html file from the public folder at the frontend to the urls.py file that is located in the backend which is in another backend folder

FOLDERS STRACTURE:

backend
    -> backend
        -> urls.py
frontend
    -> public
        -> index.html

here is where I need to put that route so python will find my index.html file

from django.contrib import admin
from django.urls import include,path
from .routers import router
from django.views.generic import TemplateView

urlpatterns = [
    path('', TemplateView.as_view(template_name = '../../public/index.html')),
]

I use VueJs in the frontend, that why I want to work organized and have dedicated frontend + backend libraries

1 Answer 1

1

In django, you can config the templates folder in settings.py, then, use the path inside this folder/s. Like this:

{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': ['PATH_OF_YOU_TEMPLATES_FOLDER'], #Probably finished in ...public/
    'APP_DIRS': True,
    'OPTIONS': {
        # ... some options here ...
    },
},]

And into the url:

from django.contrib import admin
from django.urls import include,path
from .routers import router
from django.views.generic import TemplateView

urlpatterns = [
    path('', TemplateView.as_view(template_name = 'index.html')),
]

You need to read the documentation of django templates (https://docs.djangoproject.com/en/3.0/topics/templates/).

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.