I'm new to Django, and I am trying to show my DB on a web page being able to edit it.
This is my views.py
def task1(request):
if request.POST:
form = AuthorForm(request.POST)
if form.is_valid():
form.save()
return render(request,'tasks/index.html')
else:
form = AuthorForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('tasks/task1.html', {'authors':Author.objects.all()})
This way i can print my database on webpage
But i also want to be able to add new records to it
I used
return render_to_response('tasks/task1.html',args)
But how can i send both? As far as i understood there must be a dictionary.
Here's a template
{% extends "tasks/index.html" %}
{% load bootstrap3 %}
{% load staticfiles %}
{% bootstrap_css %}
{% bootstrap_javascript %}
{% bootstrap_messages %}
{% block tasks %}
<p>31231</p>
<form action="/task1/" method="post">{% csrf_token %}
<ul>
{{ form.as_table}}
</ul>
<input type="submit" value="Create" />
</form>
{% if authors.count > 0 %}
{% for author in authors %}
<ul>
{{author.id}} {{author.name}} {{author.body}}
</ul>
{{% endfor %}
{{% endif %}
{% endblock %}