代碼展示:
templates檔案夾中的,index.html檔案:
Title 這個是從模闆中渲染的字元串
urls.py:
from django.urls import path
from front import views
urlpatterns = [
path(’’, views.index),
]
render_to_string:
views.py:
from django.template.loader import render_to_string
from django.http import HttpResponse
def index(request):
html = render_to_string(“index.html”)
return HttpResponse(html)
render:
from django.shortcuts import render
def index(request):
#html = render_to_string(“index.html”)
#return HttpResponse(html)
return render(request,‘index.html’)