# | Likes | Tech tags | Title | Creator | Created date |
---|---|---|---|---|---|
1 | 0 |
Django
|
2022-10-02 21:56
|
Uses the Django template language to generate a response, using a variable from inside the server backend code for content.
django_sample
set up, as shown here: Writing your first Django app, part 1: Creating a project - djangoproject.comexample
set up, as shown here: Writing your first Django app, part 1: Creating the Polls app - djangoproject.comdjango_sample
url configuration needs to include urls from the example
app inside django_sample\urls.py
. Example from Algotekadjango_sample\settings.py
...
INSTALLED_APPS = [
'example.apps.ExampleConfig', # Make the template documents available
...
]
example\urls.py
from django.urls import path
import example.views as views
urlpatterns = [
path('template-sample', views.view_template_sample, name='template_sample'), # Responds to the /template-sample url
]
example\views.py
from django.shortcuts import render
def view_template_sample(request):
str_var = "Hello World!"
return render(request, "sample.html", {'str_variable': str_var})
example\templates\sample.html
<document>
<body>
{{ str_variable }}
</body>
</document>
functions | |
django.shortcuts.render |
docs.djangoproject.com |
django.urls.path |
docs.djangoproject.com |
Use a templating engine to generate an HTML response for some document. The process should use a string variable to generate some of the content.