Thank you Daniel, I didn't know this! I am going to lookup how to use 
session. Thanks!

On Monday, 19 January 2015 17:13:10 UTC+8, Daniel Roseman wrote:
>
> On Monday, 19 January 2015 07:28:14 UTC, Cheng Guo wrote:
>>
>> Hello,
>>
>> I am new to Django and I have run into an issue with views.py.  I 
>> understand that there is a function behind each view. For a view that I am 
>> currently writing, it accepts a file upload from user and stores the file 
>> on the server. To do that, I need to:
>>
>> 1. check the file extension is correct
>> 2. generate a SHA-1 id for the file based on its content
>> 3. write the file to disk
>> 4. save information about the file to database
>>
>> (oh, I also created two global variables as well)
>>
>>
> Others have pointed out ways to split this up, but I wanted to pick up on 
> the last sentence. You really really should not be setting global variables 
> in your view, especially in response to user input. Global variables are 
> shared by all requests in a process, and you can't guarantee either that 
> all requests will be from the same user, or even that the same user will 
> hit the same process in subsequent requests. Don't do this: if you need to 
> store state between requests, use the db or the session.
> --
> DR.
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/45f7fdbf-45e6-4616-9204-effb4ef4c528%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to