You might want to try adding:
request.session.modified = True ( or modify your settings file to save
every request by setting the SESSION_SAVE_EVERY_REQUEST to True )

Because from this note from Django Session docs:
# Session is modified.
request.session['foo'] = {}

# Gotcha: Session is NOT modified, because this alters
# request.session['foo'] instead of request.session.
request.session['foo']['bar'] = 'baz'


On Jul 9, 10:50 am, flynnguy <[EMAIL PROTECTED]> wrote:
> Ok, I upgraded to the development version of django and that didn't
> help. I then started to try and trim out the code so it was of a more
> manageable size to post here. It's still rather large but if it helps
> anyone visualize what I'm talking about, here it is:
>
> ## test_indexs.html
> <h4>Take the Test</h4>
> <form action="." method="post">
> <table>
> {{ form }}
> </table>
> <input type="submit" value="Take Test" />
> </form>
>
> ## take_tests.html
> {{ questions_asked }}
>
> {% if score_page %}
>     {{ num }}
>     <h1 id="your_score">Your score is: {{ score|floatformat:2 }}%
> ({{ num_correct }}/{{ total }})</h1>
>     <img id="score_tach" src="/flight/grade/tach.gif?
> score={{ score }}" />
> {% else %}
>
>     <h3>{{ question.id }} {{ question.question }}</h3>
>     <form method="post" action=".">
>     <input type="hidden" name="number_of_questions" value="{{ num }}" /
>
>     <ul>
>     {% for answer in answers %}
>         <li class="answers"><input type="submit" name="{{ answer.0 }}"
> value="{{ answer.1 }}" /></li>
>     {% endfor %}
>     </ul>
>     </form>
> {% endif %}
>
> ## views.py
> def sessiontest(request):
>     if 'questionlist' inrequest.session:
>         questions_asked =request.session['questionlist']
>     if request.method == "POST":
>         ifrequest.session.get('num_questions',False):      # If there
> is a GET var called num_questions
>             ifrequest.session['current_question'] 
> <request.session['num_questions']:
>                request.session['current_question'] += 1
>                 question = Question.objects.order_by('?')[0]    # Get
> a random question
>                request.session['previous_question'] = question
>                 answers = list(enumerate([question.correct_answer,
> question.other_answer_1, question.other_answer_2]))
>                 shuffle(answers)
>                 try:
>                    request.session['questionlist'] =
> questions_asked.append(int(question.id))
>                 except AttributeError:
>                    request.session['questionlist'] =
> [(int(question.id)),]
>
>                 return render_to_response('take_tests.html',
> {'current_num':request.session['current_question'], \
>
> 'num':request.session['num_questions'], \
>
> 'question':question, \
>
> 'first_page':False, \
>
> 'questions_asked':questions_asked, \
>
> 'answers': answers})
>             else:
>                 score = (float(request.session['num_correct'])/
> float(request.session['num_questions']))*100
>                 return render_to_response('take_tests.html',
> {'correct':request.session['num_correct'], \
>
> 'total':request.session['num_questions'], \
>
> 'score':score, \
>
> 'score_page':True, \
>
> 'num_correct':request.session['num_correct'] })
>         else:   # No num_questions var set... show/process form
>             form = TestForm(request.POST)
>             if form.is_valid():
>                 num_questions =
> form.cleaned_data['number_of_questions']
>                request.session['num_questions'] = num_questions
>                request.session['current_question'] = 1
>                request.session['num_correct'] = 0
>                 question = Question.objects.order_by('?')[0]    # Get
> a random question
>                request.session['previous_question'] = question
>                 answers = list(enumerate([question.correct_answer,
> question.other_answer_1, question.other_answer_2]))
>                 shuffle(answers)
>                request.session['previous_answers'] = answers
>                request.session['questionlist'] = [int(question.id),]
> #                topics = request.POST['topics']
>                 return render_to_response('take_tests.html',
> {'current_num':request.session['current_question'], \
>
> 'num':num_questions, \
>
> 'first_page':True, \
>
> 'questions_asked':request.session['questionlist'], \
>
> 'question':question, 'answers': answers,})
>     else:
>         # Remove num_questions session key in case it is hanging
> around
>         try:
>             delrequest.session['num_questions']
>         except KeyError:
>             pass
>         form = TestForm()
>     return render_to_response('test_indexs.html', {'form':form})
>
> ###### End Code #######
>
> If there is a problem storing lists in the session variables, then I
> can look at some other method. I just thought this would be the best
> solution. Also it works some of the time, just not all of the time. I
> don't understand why it's getting set to 'None'.
> -Chris


--~--~---------~--~----~------------~-------~--~----~
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