I want to incorporate a user login form on virtually all of my sites
main pages. I felt that the best way to do this was to use an
inclusion template tag to display the form on each of the relevant
pages.

I have a base.html template which is extended using several sub
templates. The template tag that calls the Login form is in the
base.html template.

This works fine to display the empty form, but I am not able to
process the form Post request to my view. It simply returns the blank
form. I've messed around with passing a context to the template tag,
but with no success. This is because the tag expects some arguments
which are not always passed in the case of an empty form.

If I use the form as the argument, I'm not sure how to process this
back to the validation code in my view.

I've had some success by displaying the empty form using the template
tag and then overwriting the template block when the form is Posted
(using the same html in another template). This allows the data to be
validated by   my view, but it prevents display of the other sub
templates that were originally displayed in my view, because my form
calls another URL to process my login view.

Can anyone suggest the cleanest way to do this?
How can I retain the detail of my original view whilst processing the
form?

My Code fragments are as below(I know the tag will not work as is):

template_tags.py
------------------------
@register.inclusion_tag('tags/logintag.html')
def show_login(Form=None):
    if Form is None:
        form = UserLoginForm()
# I know I need some means here to pass arguments to the form
      #shows the login tag
    return {'form':form}

Views.py
-------------
def userloginscreen(request):
    #handles user login data
            template_name="admin/login.html"
            if request.method == 'POST':
                form=UserLoginForm(request.POST)
                if form.is_valid():
                   # validation code....
                 else:
                    form=UserLoginForm()
            return render_to_response(template_name,{'form':form})

Base.html
--------------
{% block account_status %}
{% if user.is_authenticated %}
        <!-- Account Status widget-->
            {% show_status %}
        <!-- widget end -->
 {% else %}
        <!-- Login in Widget -->
              {% show_login %}
        <!-- account login widget end -->
 {% endif %}
  {% endblock %}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to