Answer the question
In order to leave comments, you need to log in
In order for a dynamic variable to take on a new value, you have to restart the server in Django, how to solve it?
I recently started diving into programming in general, and I ran into a problem in Django: following the tutorial, I set a variable that should be passed to the html page, everything seems to be fine, but exactly until the variable value changes, the previously set variable is displayed on the page (or if the variable is only set, then nothing is displayed), and in order for it to be displayed, you have to restart the
views.py server
from django.shortcuts import render
# Create your views here.
def index(request):
context = {
'name': 'Nick',
'age': 24
}
return render(request, 'index.html', context)
<h1>Hi, {{name}}<br>You are {{age}} years old</h1>
Answer the question
In order to leave comments, you need to log in
It is logical, because these are not dynamic variables, but hard-coded ones.
Gunicorn has the ability to autoload if the code has changed, you can use it.
Use the values from the file (env) with environment variables and the dotenv package, try to rewrite your file with new variable values
https://stackoverflow.com/questions/63837315/chang...
from django.shortcuts import render
# Create your views here.
def index(request):
context = {
'name': var_name,
'age': var_age
}
return render(request, 'index.html', context)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question