2
You need to include the cleaned data in the template context. However, cd
is only defined when the form is valid, so you can do something like:
data = {
'post': post,
'form': form,
'sent': sent,
}
if sent:
data['cd'] = cd
return render(request, 'blog/post/share.html', data)
Since you donโt need the entire cd
dictionary in the template, another option would be to pass only the variable you need, cd['to']
.
data = {
'post': post,
'form': form,
'sent': sent,
}
if sent:
data['sent_to'] = cd['to']
return render(request, 'blog/post/share.html', data)
Then in your template, you would use {{ sent_to }} instead of {{ cd.to }}
0
cd
is only used within your view, but it is not a context variable.
To make it a context variable and accessible in the template you have to add it to your existing context variables:
return render(request, 'blog/post/share.html', {'post': post,
'form': form,
'sent': sent,
'cd': cd})
- [Answered ]-Angular -Js $http.post not working in django
- [Answered ]-A way to save the generated HTML from Django Views?
- [Answered ]-Send Email Issue โ Google Compute Engine VM
0
You need to add to
or cd
to your context:
return render(request, 'blog/post/share.html', {'post': post,
'form': form,
'sent': sent})
For example:
{'cd': cd,
'post': post,
'form': form,
'sent': sent}
- [Answered ]-Django: manage.py works fine but django-admin fails
- [Answered ]-How do I merge two django db's?
- [Answered ]-Django loop over modelchoicefield queryset
- [Answered ]-Why does the js function need to be inside the html file and cannot be separates in this case?
- [Answered ]-'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) when i add ForeignKey relation in model
Source:stackexchange.com