I'm having some trouble understanding the behaviour of inclusion tags.
I have the following relevant files
base.html (the base template)
<!DOCTYPE html>
<html lang="en">
{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'tags/style.css' %}">
{% load my_tags %}
<head>
<div class="back">
<h1> Flux </h1>
<hr>
</div>
</head>
{% block sidebar %}
{% endblock %}
{% block eventlist %}
{% endblock %}
{% sidebar %}
</body>
</html>
start.html (which at the moment does nothing)
{% extends "base.html" %}
views.py
def start(request):
return render_to_response("tags/start.html",{},
context_instance=RequestContext(request))
my_tags.py (my inclusion tag, SeeTagForm is just a textfield form)
@register.inclusion_tag("tags/sidebar.html",takes_context=True)
def sidebar(context):
seetagform = SeeTagForm()
return {"seetagform":seetagform}
sidebar.html
<form action="" method="POST">
{% for error in seetagform.name.errors %}
<p> {{ error }} </p>
{% endfor %}
{% csrf_token %}
<button class="btn" type="submit" name="seetag">See</button>
{{ seetagform.name }}
</form>
Now I have a small list of doubts:
1 - Since I have takes_context=True
in my tag, which members does the context
argument have?
2 - More specificly, how could I handle from submission from/trough my tag, that is, could I do request = context["request"]
inside sidebar(context)
so that I could check, for example, if the input was correct?
3 - To do any of the prior, do I have to add anything to the setting.py?
4 - Is it possible (and good practise) to handle the form in the inclusion tag, or should I use yet another view to do that? If so, how?
Thanks in advance,