0
I have a problem with a test I have to deliver for a selection process I’m conducting. I’ve tried every possible and imaginable way to solve it, but I couldn’t. When trying to call an index.html file that is inside a templates/api folder so that it becomes the root of the url (http://127.0.0.1:8000) Django doesn’t recognize her. Follows codes:
File urls.py of my folder sisquestoes(root, folder that contains setings.py): PS: I already changed the name of this api and still does not locate the template .
urlpatterns = [
path(r'admin/', admin.site.urls),
path('', include('api.urls')),
url(r'^', include('api.urls','app_name')),
]
Api folder urls.py file (which has the admin.py folder and the files and templates/api/index.html):
router = routers.DefaultRouter()
router.register('questoes', views.QuestoesView)
router.register('user', views.UserView)
app_name="api"
urlpatterns = [
path('', include(router.urls)),
url(r'^$', views.index, name='index'),
]
Function in views.py:
from django.shortcuts import render
from . import views
def index(request):
return render(request,'api/index.html')
I honestly spent the whole night trying to solve read virtually all documentation, I went through various paths and tutorials and nothing. I am waiting for some solidarity and dear soul. Great hug.
If you use the Rest framework, why render an index? Does that make sense? Ideally you should serve a restful api. Rendering html should not be the responsibility of the Rest framework, this is my opinion. If I could explain better the use case.
– Danizavtz