I have a class based django view that presents some tables and text to the user dependent on their inputs.
I would like to have a button on this page that allows the user to download this data as a word document.
What would be the best way to accomplish this?
urls.py
app_name = "patient"
urlpatterns = [
path('add/', views.PatientAddView.as_view(), name="patient_add"),
path(
route='<patient_id>/',
view=views.TreatmentTemplateView.as_view(),
name='treatment_detail'),
]
views.py
class TreatmentTemplateView(TemplateView):
template_name = "../templates/patient/treatment_detail.html"
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs)
context["patient_id"] = self.kwargs["patient_id"]
result = find_treatment(context["patient_id"])
context = result[0]
context["patient"] = result[1]
return context
hmtl
{% extends "base.html" %}
<!-- {% block title %}Patient: {{ patient.name }}{% endblock %} -->
{% block content %}
<h3>Patient Summary</h3>
<p>
{{pt_letter|linebreaks}}
</p>
<br>
<br>
<h3>Current Medication</h3>
<p>
{{current_med_letter|safe}}
</p>
<br>
<br>
<h3>Past Medication</h3>
<p>
{{past_med_letter|safe}}
</p>
<br>
<br>
<h3>Plan </h3>
<br>
<h5>Treatment Recommendation</h5>
<p>
{{newmed_letter|safe}}
{{existingmed_letter|safe}}
</p>
<br>
<h5>Physical Health Monitoring</h5>
<p>
{{monitor_letter|safe}}
</p>
<br>
<h5>Potential Drug Interactions</h5>
<p>
{{interaction_letter|safe}}
</p>
{% endblock content %}