views:

46

answers:

1

Recently I upgraded my django server. Going from 1.2 to a new version. The forms exhibit a strange behavior. When a field is left blank the whole page simply refreshes, rather than showing errors like I remember. What could cause this? What ought I do to fix it?

{%extends "baseAUTH.html" %}
    {% block title  %}
    {{ title }}
    {% endblock %}


    {% block content %}
{% load adminmedia %}

<script type="text/javascript">
window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";
</script>


<script type="text/javascript" src="/admin/jsi18n/"></script>
<script type="text/javascript" src="/media/js/core.js"></script>
<link rel="stylesheet" type="text/css" href="/media/css/forms.css"/>
<link rel="stylesheet" type="text/css" href="/media/css/base.css"/>
<link rel="stylesheet" type="text/css" href="/media/css/global.css"/>
<link rel="stylesheet" type="text/css" href="/media/css/widgets.css"/>

{{ form.media }}


    <h1>{{ title }}</h1>

    {% if form.errors %}
        <p style="color: red;">
            Please correct the error{{ form.errors|pluralize }} below.
        </p>
    {% endif %}

    <form action="" method="post" enctype="multipart/form-data">
    {% csrf_token %}
        <table valign=TOP>
            {{ form.as_table }}
        </table>
        <input type="submit" value="Submit">
    </form>
    {% endblock %}
A: 

I found the issue. I reverted some changes back and found the point where I broke it. In the following function I tried to abstract

def FormToEmail(request, token, title, subject, message, reciever, attachlist):

    if request.method == 'POST':
        sender = AddSender(request)
        reciever.append(sender)

        form = token(request.POST, request.FILES)

        if form.is_valid():
            mail = EmailMessage(subject, message, sender, reciever)

            if len(attachlist) > 0:
                for item in attachlist:
                    if form.cleaned_data[item]:
                        temp = request.FILES[item]
                        mail.attach(temp.name, temp.read(), \
                            temp.content_type)

            return SendIt(request, mail)

Here to

    else:
        form = token()
    if request.user.is_authenticated():
        return render_to_response('FormTemplate.html',  \
        {'form': form, 'title' : title},  \
        context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/Webtemplate/accounts/login')

here. Into

return RenderFormForAuth(request, token(), title)

with the function defined as

def RenderFormForAuth(request, form, title):
    if request.user.is_authenticated():
        return render_to_response('FormTemplate.html',  \
        {'form': form, 'title' : title},  \
        context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/Webtemplate/accounts/login')

which broke everything. (I can paste the whole function/ how it's called if need be, but seems like a waste of space.)

Does anyone know why this wouldn't work?

duallain
can you show the complete code of the function that is handling the view. It is not clear whether you are populating the POST data into form or not
Ashok