How to build a login form on the startingpage within a little widget on the top left?
I want to have a stylish web 2.0 like login…on the upper right sliding in (like on dropbox.com)…so far the design part…
when it comes to the views and default login behavior of django (1.4) i can’t get myself to the right direction. I get the standart example to work with django.contrib.auth and so forth…
but what if i have my log-in widget on the first site:
(r’^$’, ‘myproject.views.home’)
I tried to integrate the form into my template (home.html) which looks like this:
<form action="/login/" method="post">{% csrf_token %}
{% if next %}
<input type="hidden" name="next" value="{{ next }}" />
{% endif %}
username:
<input type="text" name="username" value="{{ username}}" /><br />
password:
<input type="password" name="password" value="" /><br />
<input type="hidden" name="next" value="{{'something'}}" />
<input type="submit" value="anmelden" />
</form>
my view looks like this:
def home(request):
title='home'
try:
username = request.POST.get('username', '')
password = request.POST.get('password', '')
user = auth.authenticate(username=username, password=password)
if user is not None and user.is_active:
# Correct password, and the user is marked "active"
auth.login(request, user)
# Redirect to a success page.
return HttpResponseRedirect("/im_in/")
else:
# Show an error page
return HttpResponseRedirect("/im_not/")
except:
return render_to_response('home.html',locals())
[edit]
my urlconf:
urlpatterns = patterns('',
(r'^$', 'edumin.views.home'),
)
My problem:
after submit django leads me to /login and says:
The current URL, login/, didn’t match any of these.
Any help or a good example of having a login on the first page…or a custom login which serves this purpose?
Based on everything I see here, you don’t actually have anything at
/login/to catch the login, but instead are trying to log in via the current URL. In that case you should completely remove theactionattribute from the login form.