Django Beginner. I have a functioning Django app (models, views, urls, templates) similar to what you can see in tutorials. I would like to return some debugging and user information (e.g. if an item already exists in a table) into a terminal-like section in my base.html.
Inside my standard view function call (turning an uploaded csv file to pandas and generating inserts into my normalized tables) I added a 2nd render(request,...) that sends a dictionary to my base.html.
def bulkinsert(request):
data=None
context=None
if request.method== "POST" and request.FILES['myfile']:
myfile = request.FILES['myfile']
df=pd.read_csv(myfile )
data_html=df.to_html()
context={'data': data_html }
m=''
# now read each row and insert lot, sublot, ...
for index, row in df.iterrows():
if pd.notna(row['lot']):
lotname=row['lot']
...
# check existence of this lot
f1=Lot.objects.filter(lotname=lotname).count()
if f1==0:
m+='\n Lot did not exist yet, inserting ...'
b1=Lot(lotname=lotname)
b1.save()
else:
m+=f'\n Lot {lotname} already exists'
...
c2={ 'memo': m}
render(request, 'lenses/base.html',c2)
return render(request, 'bulkinsert.html',context)
else:
form=UploadFileForm()
data=None
context=None
return render(request, 'bulkinsert.html',context)
What do I have to add to my base.html to pass that dictionary (c2) into the desired html-section?
So far I have just:
{% block c2 %}
<p>{{ memo }}</p>
{% endblock %}
but the page does not update as I expected.