I have a simple note taking part of my application I'm trying to converge into one template. Currently, I have one template and view that renders and posts the form and another that displays the results. I'd like to amalgamate these into one where the form exists and the results are displayed on the same page.
This seems to be something that be achieved with template inheritance, but I'm not sure how to alter the views so that both of these results can appear in the same template. I've looked around for answers but can't seem to find what I need to achieve this. Any help that could also inform me on how to properly achieve this moving forward would be appreciated. This is one of those areas I've been anticipating learning but it's been more difficult that I assumed. The essential code is posted below: Views for submitting and displaying notes: @login_required def submit_note(request): if request.method == 'POST': notes_form = NotesForm(request.POST, request.FILES) if notes_form.is_valid(): new_note = notes_form.save(commit=False) new_note.author = request.user new_note.save() return HttpResponseRedirect( "" ) else: notes_form = NotesForm() return render_to_response("write_note/notes.html", {'form': notes_form}, context_instance=RequestContext(request)) @login_required def all_notes(request): all_notes = Notes.objects.all().order_by('-date') paginate = paginated_stories(request, all_notes) return render_to_response("report/notes.html", {'notes': paginate}, context_instance=RequestContext(request)) Current basic templates to submit and display: {% extends 'base.html' %} {% block page_title %}Notebook{% endblock %} {% block headline %}Notebook{% endblock %} {% block content %} <h2>Write and save notes, quotes and other story info</h2> <div class="row"> <div class="span8"> <form action="" method="post">{% csrf_token %} {{ form.as_p }} <input type="submit" class="btn btn-primary" value="Submit" /> </form> </div> </div> {% endblock %} {% extends 'base.html' %} {% block page_title %}Notebook{% endblock %} {% block headline %}Notebook{% endblock %} {% block content %} <div class="row"> <div class="span4"> {% if notes %} {% for note in user.notes.all reversed %} <h3>{{ note.title }}</h3> <p>{{ note.date }}</p> <p>{{ note.copy }}</p> {% endfor %} {% else %} <p>You have no notes stored.</p> {% endif %} </div> </div> {% endblock content %} And the two urls: url(r'^write_note/$', 'stentorian.report.views.submit_note', name='write_note'), url(r'^notes/', 'stentorian.report.views.all_notes', name='all_notes') -- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/IG6vV9MaSVoJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.