How to display information from db on the one template along with forms in django using class view?
I would like to have information from db on the right side of the page. How to display it on template? What I could add in class based view in order to see it on the template?
template
{% extends "base.html" %}
{% block content %}
<div class="container">
<div class="row">
<div class="col-sm">
<form action="" method="POST">
<table>
{{ form }}
{% csrf_token %}
</table>
<input type="submit" class="btn btn-primary" value="Submit">
</form>
</div>
<div class="col-sm">
<div class="col-sm">
<h5>Problem:</h5>
</div>
</div>
</div>
</div>
{% endblock content %}
view
class SolutionCreate(CreateView):
model = Solution
template_name = 'analysis/create_solution.html'
fields = [
'problem',
'research',
'solutions',
'resources',
'plan',
'test'
]
def post(self, request, *args, **kwargs):
form = SolutionForm(request.POST)
if form.is_valid():
form.save(commit=True)
return HttpResponseRedirect('/saved/')
return render(request, self.template_name, {'form': form})
not really clear to me what you want, but i assume you want extra context in the template.
use this in your createview
def get_context_data(self, **kwargs)
// youre context
return context
now the context is available in youre template
