views:

35

answers:

1

I am having problems running through a tutorial and it seems the problems stem from this:

(r'^l/login/$', 'django.contrib.auth.views.login'),

It seems I have done all correct, but the forms dont show. If I hit Login. I get back to the same page without forms.

Did I miss something?

Here the code:

urls.py:

from django.conf.urls.defaults import *
from formsapp.views import *
from login.views import *
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

#Forms1:
    (r'^$', main_page),
#Forms2
    (r'^register/', main_page1),
#FormsLogin:
    (r'^l/', login_main_page),
    (r'^l/login/$', 'django.contrib.auth.views.login'),
    (r'^l/logout/$', 'logout_page'),

views.py:

from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.contrib.auth import logout
from django.contrib.auth.models import User
from django.template import RequestContext
from django.shortcuts import render_to_response

def login_main_page(request):
    return render_to_response('mainpage.html', RequestContext(request))

def logout_page(request):
    logout(request)
    return HttpResponseRedirect('/l/')

base.html:

<html>

<head>

<title> {% block title %}{% endblock %}</title>

</head>

<body>
<h1>{% block head %}{% endblock %}</h1>
{% block content %}{% endblock %}
<br>
<br>
<br>
<a href="/l/">Login Main Page</a>
{% if user.is_authenticated %}
    <a href="/l/logout/">Log out </a>
{% else %}
    <a href="/l/login/">Log in </a>
{% endif %}

</body>

</html>

login.html:

{% extends "base.html" %}
{% block title %}Log in{% endblock %}
{% block head %}Log in{% endblock %}
{% block content %}
    {% if form.has_errors %}
    <p> Username or password didn't work. Please enter them again </p>
    {% endif %}

    <form method="post" action=".">
        <p><label for="id_username">Username:
            </label>{{ form.username }}</p>
        <p><label for="id_password">Password:
            </label>{{ form.password }}</p>
        <input type="hidden" name="next"
            value="/l/" />
        <input type="submit" value="Log in" />
    </form>

{% endblock %}
A: 

url pattern

(r'^l/', login_main_page),

will match any url starting with "l/" and it is placed before "l/login" so second one won't be called, you should terminate regexp with $:

(r'^l/$', login_main_page),

romke
Thanks a bilion! You are the master. That was the error!!
MacPython