First time posting on here and new to Django, sorry in advance.
Im trying to plug the name field from my model into my html template, which I will then convert to a pdf.
Everything involving the html to pdf conversion is working, I just cant seem to get the name field from my model to work into the html_template when it renders.
Ive tried adding 'name' : name into the context_dict within the render_to_pdf view, and that did not work.
I think I am likely missing something in my view.
pdf_template.html
{% block content %}
<div class="container">
<div class="row">
<p> **{{name}}** </p>
</div>
{% endblock %}
models.py
class User(models.Model):
username = models.CharField(max_length = 20, primary_key=True)
name = models.CharField(max_length = 20)
def __str__(self):
return self.name
views.py
def render_to_pdf(template_src, context_dict={}):
template = get_template(template_src)
html = template.render(context_dict)
result = BytesIO()
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
if not pdf.err:
return HttpResponse(result.getvalue(), content_type='application/pdf')
return None