Saturday, September 24, 2016

Re: Using sessions in Django

Thanks for the help, although i get an error, saying "DataError: value too long for type character varying(2000)" when i am trying to save the "Session.objects.get(session_
key=request.session.session_key)".

 I checked my db and the "session_id" column is varchar(40) (which is the default value that created because of the "models.ForeignKey(Session)" ).
Any suggestions on how to fix that? I did exactly the same thing as you guys suggested before.

On Friday, August 17, 2012 at 1:46:24 PM UTC+1, sandy wrote:
On Fri, Aug 17, 2012 at 1:28 PM, Sandeep kaur <mkaur...@gmail.com> wrote:
> I am using session foreign key in my table.

>          if not request.session.exists(request.session.session_key):
>                                 request.session.create()
>          profile.sess = request.session.session_key
>          profile.save()
>
> But when I execute my form and click on submit button, I get error as :
>
> ```Cannot assign "'b593c61453d7aad199078c66b9ad6b30'":
> "ClientJob.sess" must be a "Session" instance.````
>

Problem solved!!
Used this code :

if not request.session.exists(request.session.session_key):
            request.session.create()
profile.sess = Session.objects.get(session_key=request.session.session_key)

--
Sandeep Kaur
E-Mail: mkaur...@gmail.com
Blog: sandymadaan.wordpress.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6cdbdcf0-afeb-4ab8-b494-5356b76888f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment