Thanks a load!  You've cleared up a lot!

Yes, I have read through the tutorial.  I even wrote a shortened version of 
it to act as notes as I learn:  http://polydoo.com/code/?p=48  (my blog)

Thanks again!

On Thursday, August 2, 2012 10:42:59 AM UTC-4, Kurtis wrote:
>
> Hey Gregory,
>
> On Thu, Aug 2, 2012 at 9:06 AM, Gregory Thompson Jr. <
> spockthompso...@gmail.com> wrote:
>
>> I'd like to pass form data from one view to another.  
>>
>> Here's my attempt: 
>>
>> *#Models.py*
>> from django import forms
>> class Textizer(forms.Form):
>>     to_textize = forms.CharField(max_length=100)
>>     
>>     def __unicode__(self):
>>         return self.to_textize
>> *#views.py*
>> from textize.models import Textizer
>> from django.http import HttpResponseRedirect
>> from django.shortcuts import render_to_response
>> from django.core.context_processors import csrf
>> def index(request):
>>     if request.method == 'POST':
>>         form = Textizer(request.POST)
>>         
>>         if form.is_valid():
>>             request.session['text'] = form.cleaned_data['to_textize']
>>             return HttpResponseRedirect('/results')
>>         
>>     else:
>>         form = Textizer()
>>         
>>     c = {'form': form}
>>     c.update(csrf(request))
>>     return render_to_response('C:/Documents and 
>> Settings/quansai/projects/textsite/templates/index.html', c)
>>     def results(request):
>>     text = request.session.get('text', None)
>>     c = {'text' : text}
>>     return render_to_response('C:/Documents and 
>> Settings/quansai/projects/textsite/templates/results.html', c)
>>
>>
>> I really don't understand the following, and I've read the documentation 
>> over and over.  I've been on this for two days:
>>
>>
> No problem! I'll try to clear things up for you.
>  
>
>>
>>    - How to initiate a session
>>
>> Sessions are initiated automatically in Django using the "Session 
> Middleware". Basically, on each request, a session is either started or 
> continued (in simple terms, there's probably more to it than that but I 
> haven't inspected Django's session code too deeply)
>
> The only thing you need to do to make sure the session middleware is 
> properly configure it. It needs some sort of a storage (such as database, 
> file, cookies which are limited, etc...). You'll also need to make sure the 
> session middleware is included in your middleware configuration. This 
> configuration would exist under your settings.py and I believe is enabled 
> by default when creating new projects; at least that's been my experience 
> with Django 1.3+.
>
> Keep in mind that these do use cookies, no matter what, so you will need 
> them enabled in whatever HTTP Client (browser, or what-not) you use.
>
> Two links for enabling and configuring sessions (both on the same page, 
> these are anchor links).
>
> Enabling Sessions: 
> https://docs.djangoproject.com/en/dev/topics/http/sessions/?from=olddocs/#enabling-sessions
> Configuring Sessions: 
> https://docs.djangoproject.com/en/dev/topics/http/sessions/?from=olddocs/#configuring-the-session-engine
>
>
>>    - How sessions are checked
>>
>> I'm not quite sure what you mean, here. Sessions are checked to be valid 
> by Django by signing them, but this is done by the middleware. If you want 
> to check whether a session exists, you might be asking more along the lines 
> of checking to see whether a user is authenticated. Or, you may be asking 
> how to check whether a certain variable is available from the session. 
> Since I'm not sure which part your looking for information on, I'll give 
> you information on both:
>
> To check if a particular object exists within the current session, follow 
> the example under __contains__(key) which actually does not call "contains" 
> but instead uses "if x in request.session": 
> https://docs.djangoproject.com/en/dev/topics/http/sessions/?from=olddocs/#using-sessions-in-views
>
> To check whether a current user is authenticated (logged in), you could 
> use this example: 
> https://docs.djangoproject.com/en/dev/topics/auth/#authentication-in-web-requests
>  
>
>>
>>    - How to retrieve form data from one page to handle the data on another.
>>
>>
> Retrieving Form Data is actually one of Django's extremely strong points 
> (in my opinion) although it does require a bit of a learning curve. Once 
> you get it down, it takes off a huge burden; especially when coming from 
> other frameworks that don't offer as much validation built in. Basically, 
> you subclass a Form, create an instance of your form in the view while 
> passing it the POST data, and it will validate that data. Then, you can 
> simply do some flow-control based upon "if form.is_valid()".
>
> Handling the data on another view is sort of a vague question. I'm not 
> quite sure what you mean by this one but please feel free to elaborate and 
> I'll see if I can give you some more info here.
>  
>
>> Again, I've read through the documentation.  I've asked on IRC but everyone 
>> pretty much just says "RTFM" even when I tell them I have.  This is 
>> absolutely frustrating as an extreme beginner.
>>
>>
> Weird. Most people just suggest reading the Tutorial. Have you given that 
> a shot? It really does help with diving into the functionality and doesn't 
> take too long considering the large amount of knowledge you gain about 
> Django from it.
>  
>
>>
>> I'd also like to add that I DO understand the core Python language.  Please, 
>> unless it's absolutely necessary, don't try explaining to me what a 
>> dictionary, tuple, list, etc... is.  I've already had my intelligence 
>> insulted by the users on IRC in this regard.  I really just don't understand 
>> the sessions documentation. 
>>
>>  -- 
>>
>
> Sorry to hear about your frustration. I recommend trying out the tutorial 
> if you haven't given it a shot, yet, and maybe break your questions up into 
> smaller peices when you ask them on here. Including your shot at the code 
> was a good show of attempt. I'm not sure what exact problems you're having 
> with your code but it may be helpful to yourself to break it down to the 
> smallest body of functionality that will emulate what you're attempting to 
> see where it's going wrong. Taking out the Form and testing sessions with 
> two views might be a good way to start.
>  
> Good luck!
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/oDKUiofRiQ8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to