| Name | gene |
|---|---|
| Email Address | n/a |
| Posts | 11 |
-
- 2010-07-06 15:10:41
- Re: form html isn't being passed along by templating system
- Board » Django » Templates
-
Good guess, that was right.
-
- 2010-07-05 10:47:34
- Re: form html isn't being passed along by templating system
- Board » Django » Templates
-
Any idea why it brings me back to the same page when I submit the form?
-
- 2010-07-04 10:52:42
- Re: form html isn't being passed along by templating system
- Board » Django » Templates
-
ahh ok. The tutorial emphasized RequestContext for the view that processes the form.
Yeah, I changed that and I'm not getting an error anymore it's just taking me back to the same page. I'll dabble some more from here. Thanks!
-
- 2010-07-04 10:41:19
- Re: form html isn't being passed along by templating system
- Board » Django » Templates
-
same html viewed from the browser
<form action="login.html" method="post"> <input type="text" name="username" id="Username" value="Username" /> <input type="text" name="password" id="Password" value="Password" /> <input type="submit" value="Vote" /> </form>
-
- 2010-07-04 10:39:11
- Re: form html isn't being passed along by templating system
- Board » Django » Templates
-
Here's what I got from the shell. I don't know if this has everything you need. Especially since I wasn't able to pass along a "request" into the RequestContext
>>> print t.render(Context()) /usr/lib/python2.6/dist-packages/django/template/defaulttags.py:52: UserWarning: A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext. warnings.warn("A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext.") <form action="login.html" method="post"> <input type="text" name="username" id="Username" value="Username" /> <input type="text" name="password" id="Password" value="Password" /> <input type="submit" value="Vote" /> </form> >>> print t.render(RequestContext()) Traceback (most recent call last): File "<console>", line 1, in <module> TypeError: __init__() takes at least 2 arguments (1 given) >>> print t.render(RequestContext(request)) Traceback (most recent call last): File "<console>", line 1, in <module> NameError: name 'request' is not defined >>>
--- Last Edited by gene at 2010-07-04 10:39:24 ---
-
- 2010-07-04 10:11:44
- Re: form html isn't being passed along by templating system
- Board » Django » Templates
-
I'm not sure if this is what you're looking for. This is the html of the error page.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="robots" content="NONE,NOARCHIVE"> <title>403 Forbidden</title> <style type="text/css"> html * { padding:0; margin:0; } body * { padding:10px 20px; } body * * { padding:0; } body { font:small sans-serif; background:#eee; } body>div { border-bottom:1px solid #ddd; } h1 { font-weight:normal; margin-bottom:.4em; } h1 span { font-size:60%; color:#666; font-weight:normal; } #info { background:#f6f6f6; } #info ul { margin: 0.5em 4em; } #info p { padding-top:10px; } #summary { background: #ffc; } #explanation { background:#eee; border-bottom: 0px none; } </style> </head> <body> <div id="summary"> <h1>Forbidden <span>(403)</span></h1> <p>CSRF verification failed. Request aborted.</p> </div> <div id="info"> <h2>Help</h2> <p>Reason given for failure:</p> <pre> No CSRF or session cookie. </pre> <p>In general, this can occur when there is a genuine Cross Site Request Forgery, or when <a href='http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ref-contrib-csrf'Django's CSRF mechanism</a> has not been used correctly. For POST forms, you need to ensure:</p> <ul> <li>The view function uses <a href='http://docs.djangoproject.com/en/dev/ref/templates/api/#subclassing-context-requestcontext'<code>RequestContext</code></a> for the template, instead of <code>Context</code>.</li> <li>In the template, there is a <code>{% csrf_token %}</code> template tag inside each POST form that targets an internal URL.</li> <li>If you are not using <code>CsrfViewMiddleware</code>, then you must use <code>csrf_protect</code> on any views that use the <code>csrf_token</code> template tag, as well as those that accept the POST data.</li> </ul> <p>You're seeing the help section of this page because you have <code>DEBUG = True</code> in your Django settings file. Change that to <code>False</code>, and only the initial error message will be displayed. </p> <p>You can customize this page using the CSRF_FAILURE_VIEW setting.</p> </div> </body> </html>
-
- 2010-07-04 10:04:57
- Re: form html isn't being passed along by templating system
- Board » Django » Templates
-
yeah, my original attempt looks like this. Same error message both ways.
# Create your views here. from django.template import Context, RequestContext, loader from login.models import Username from django.http import HttpResponse from django.shortcuts import render_to_response from django.core.context_processors import csrf def index(request): t = loader.get_template('login/index.html') return render_to_response('login/index.html') def login(request): return render_to_response("login/login.html", context_instance=RequestContext(request))
--- Last Edited by gene at 2010-07-04 10:05:26 ---
-
- 2010-07-04 09:54:53
- Re: form html isn't being passed along by templating system
- Board » Django » Templates
-
It's rendering correctly but now I have a CSRF token failure. I'm doing everything according to the tutorials though. Any idea?
Reason given for failure: No CSRF or session cookie.
template<form action="login.html" method="post"> {% csrf_token %} <input type="text" name="username" id="Username" value="Username" /> <input type="text" name="password" id="Password" value="Password" /> <input type="submit" value="Vote" /> </form>
views.py# Create your views here. from django.template import Context, RequestContext, loader from login.models import Username from django.http import HttpResponse from django.shortcuts import render_to_response def index(request): t = loader.get_template('login/index.html') return render_to_response('login/index.html') def login(request): c = {} c.update(csrf(request)) return render_to_response("login/login.html", c)
--- Last Edited by gene at 2010-07-04 09:55:37 ---
-
- 2010-07-04 09:14:56
- Re: form html isn't being passed along by templating system
- Board » Django » Templates
-
Thanks
Is there a way render a template object that has no variables? I tried doing t.render() but I got an error saying render needs at least one parameter.
-
- 2010-07-04 08:18:09
- Re: form html isn't being passed along by templating system
- Board » Django » Templates
-
My understanding was the render method replaces all django variables with their values. Since I have no variables in my template why is this necessary?


