Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Dec. 30, 2010 16:36:31

a.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

User authentication in Django


Hi guys,

I'm attempting to follow the very simple setup for user authentication
in Django as detailed in the documentation here:http://docs.djangoproject.com/en/dev/topics/auth/I've got a database synced, the apps installed as detailed, but when I
attempt to access a password protected url it gives me the following
404 message:

Using the URLconf defined in logintest.urls, Django tried these URL
patterns, in this order:
^logintest/
^admin/doc/
^admin/
^secret/
The current URL, accounts/login/, didn't match any of these.

Secret is the app that simply renders a page that says 'secret'. It
works fine when the @login decorator is commented out.

Any ideas?

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Dec. 30, 2010 17:16:02

a.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

User authentication in Django


okay, so I added a url directing accounts/login requests to a view
which in turn directs it to the login.html template suggested athttp://docs.djangoproject.com/en/dev/topics/auth/Which is:

{% extends "base.html" %}
{% load url from future %}

{% block content %}

{% if form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

<form method="post" action="{% url 'django.contrib.auth.views.login'
%}">
{% csrf_token %}
<table>
<tr>
<td>{{ form.username.label_tag }}</td>
<td>{{ form.username }}</td>
</tr>
<tr>
<td>{{ form.password.label_tag }}</td>
<td>{{ form.password }}</td>
</tr>
</table>

I've taken out the "base.html" stuff. When I now submit a user and
login (even though I've not yet created a user) I expect to see {% if
form.errors %}
<p>Your username and password didn't match. Please try again.</p>
{% endif %}

However instead I get an error: CSRF verification failed. Request
aborted.

Any ideas?

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Dec. 30, 2010 17:24:17

a.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

User authentication in Django


Okay, that problem is fixed. I just added the /accounts/login to the
url file.

New problem:

my login page is giving me: CSRF verification failed. Request aborted

This is the html from login.html

{% block content %}

{% if form.errors %}
<p class="error">Sorry, that's not a valid username or password</
p>
{% endif %}

<form action="" method="post">
{% csrf_token %}
<label for="username">User name:</label>
<input type="text" name="username" value="" id="username">
<label for="password">Password:</label>
<input type="password" name="password" value="" id="password">

<input type="submit" value="login" />
<input type="hidden" name="next" value="{{ next|escape }}" />
</form>

{% endblock %}

Any ideas?

Cheers,
Aaron

On Dec 30, 4:33 pm, aaron <aaron.jerl...@gmail.com> wrote:
> Hi guys,
>
> I'm attempting to follow the very simple setup for user authentication
> in Django as detailed in the documentation here:
>
>http://docs.djangoproject.com/en/dev/topics/auth/>
> I've got a database synced, the apps installed as detailed, but when I
> attempt to access a password protected url it gives me the following
> 404 message:
>
> Using the URLconf defined in logintest.urls, Django tried these URL
> patterns, in this order:
> ^logintest/
> ^admin/doc/
> ^admin/
> ^secret/
> The current URL, accounts/login/, didn't match any of these.
>
> Secret is the app that simply renders a page that says 'secret'. It
> works fine when the @login decorator is commented out.
>
> Any ideas?

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Dec. 30, 2010 19:10:41

a.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

User authentication in Django


According to the docs you just need to add
{% csrf_token %}

to each form.

sorry for the noise.

On Dec 30, 5:15 pm, aaron <aaron.jerl...@gmail.com> wrote:
> okay, so I added a url directing accounts/login requests to a view
> which in turn directs it to the login.html template suggested at
>
>http://docs.djangoproject.com/en/dev/topics/auth/>
> Which is:
>
> {% extends "base.html" %}
> {% load url from future %}
>
> {% block content %}
>
> {% if form.errors %}
> <p>Your username and password didn't match. Please try again.</p>
> {% endif %}
>
> <form method="post" action="{% url 'django.contrib.auth.views.login'
> %}">
> {% csrf_token %}
> <table>
> <tr>
>     <td>{{ form.username.label_tag }}</td>
>     <td>{{ form.username }}</td>
> </tr>
> <tr>
>     <td>{{ form.password.label_tag }}</td>
>     <td>{{ form.password }}</td>
> </tr>
> </table>
>
> I've taken out the "base.html" stuff. When I now submit a user and
> login (even though I've not yet created a user) I expect to see {% if
> form.errors %}
> <p>Your username and password didn't match. Please try again.</p>
> {% endif %}
>
> However instead I get an error: CSRF verification failed. Request
> aborted.
>
> Any ideas?

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 21st of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support