index.html:
{% if user.is_authenticated %}
you are logged in!
{% else %}
<h3>Login</h3>
<form action="/login" method="post" accept-charset="utf-8">
{% csrf_token %}
<label for="username">Username</label><input type="text" name="username" value="" id="username" />
<label for="password">Password</label><input type="password" name="password" value="" id="password" />
<p><input type="submit" value="Login →"></p>
</form>
{% endif %}
views.py:
def main(request):
respuesta=""
salida=""
lista=Hotel.objects.all()
listauser=Users.objects.all()
if len(lista) == 0:
print("Parsing....")
theParser = make_parser()
theHandler = myContentHandler()
theParser.setContentHandler(theHandler)
fil = urllib2.urlopen( 'http://www.esmadrid.com/opendata/alojamientos_v1_es.xml')
theParser.parse(fil)
template = get_template("index.html")
if request.user.is_authenticated():
return HttpResponse(template.render({'lista':lista[mini:maxi],'user':request.user.username,'listausers':listauser,'condicion':""}))
else:
return HttpResponse("Not logged in"+"<a href=login"+"> Log in</a>")
I get a CSRF Forbbiden bug, how can I fix it?