On Thursday 10 September 2009 10:45:01 Benjamin Kreeger wrote: > Okay, I just made myself think, which is dangerous. When I removed the > @login_required decorator from the view that handles the POST data, it > worked. > > But I'd really like the form to require the user to be logged in (as > part of the form brings up information about the user from > request.user). > > On Sep 10, 12:41 pm, Benjamin Kreeger <[email protected]> > > wrote: > > And for what it's worth, the view asks for authentication using a > > @login_required decorator (and django.contrib.auth), and that's all > > hunky-dory, too. Haven't had any problems with that part of it before. >
You can try to hard code what the decorator does[1] in your view function:
def uploadform(request):
if not request.user.is_authenticated():
return HttpResponse("You must be logged in to access this page")
The other option is to do this in your template and render the form if the
user is authenticated.
{% if request.user.is_authenticated %}
{% form %}
{% else %}
<h2>You must be logged in to access this page</h2>
{% endif %}
Or a combonation:
def uploadform(request):
logged_in = True
if not request.user.is_authenticated():
logged_in = False
return render_to_response('upload.html', {'logged_in':
logged_in },
context_instance=RequestContext(request))
in upload.html:
{% if logged_in %}
{% form %}
{% else %}
<h2>You must be logged in to access this page</h2>
{% endif %}
Or any variation of these.
Hope this helps,
Mike
[1] http://docs.djangoproject.com/en/dev/topics/auth/#limiting-access-to-
logged-in-users-that-pass-a-test
--
Promise her anything, but give her Exxon unleaded.
signature.asc
Description: This is a digitally signed message part.

