Monday, May 30, 2016

Re: Simultaneous Web Requests appending responses in function based views

I don't see anything in your pasted code that would cause that in the browser. Have you provided us a complete example that exhibits that behavior? Reduce your project down to the smallest set of code that exhibits the problem and then upload it somewhere we can see it.

On Mon, May 30, 2016 at 8:13 PM, cr katz <crkatz411@gmail.com> wrote:
Single request from the user gives the correct output as below. Please see the appended response further below when a user submits 2 requests from 2 different browsers on the same dev machine.

I don't want the users to see appended responses, rather, each request must return response as intended with in the request context.

Hello, I am A
Hello, I am X
Hello, I am B
Hello, I am Y


Appended response when user submits 2 requests simultaneously from 2 diff browsers:

Hello, I am A
Hello, I am X
Hello, I am B
Hello, I am Y
Hello, I am A
Hello, I am B

On Monday, May 30, 2016 at 6:52:12 PM UTC-4, Stephen Butler wrote:
What's your actual output vs. what's your desired output?

Also, the RequestContext is meant for the render() function. If you just want to access request.GET then you can do it directly (request is passed in as the first parameter to your view func). You also don't need to pre-assign qList and cd, as long as they are assigned before they are accessed you are OK.

On Mon, May 30, 2016 at 5:18 PM, cr katz <crka...@gmail.com> wrote:
Hello James,
        Here below is my code:

qList in the code below, actually take a list of functions and uses the parameters received thru the request, processes and appends the response to 'p'. In this code, I eliminated those functions and hardcoded with a list of strings.

def search(request):

p = []
cd = {}
qList=[]
request_context = RequestContext(request)

if request_context.request.GET:
form = SearchForm(request_context.request.GET)
# print form
if form.is_valid():
cd = request_context.request.GET
projectId = cd['project']
app = cd['app']
if cd['days'] != '0':
daysAgo = '-' + cd['days']
else:
daysAgo = cd['days']
sdtime = cd['sdtime']
edtime = cd['edtime']

qList = ["Hello, I am X", "Hello, I am Y", "Hello, I am A", "Hello, I am B"]

for func in qList:
print func
t.sleep(10)
p.append(func)
context = {'query_output': p, 'id_project': projectId,
'app': app, 'pOutput': p}
return render(request, 'temp.html', context)

else:
form = SearchForm()
return render_to_response('search_form.html', {'form': form})

Thanks
crkatz

On Monday, May 30, 2016 at 2:10:17 AM UTC-4, James Schneider wrote:


On May 29, 2016 4:23 PM, "cr katz" <crka...@gmail.com> wrote:
>
> Hello,
>         I am new to django. I developed a web application using form based views. When I submit a single web request from the dev env, the response is returned correctly. When submit 2 simultaneously from 2 browsers, I see appended responses for each request. 
>
> How can I process requests independently?

That would certainly be odd behavior, although I'm not exactly sure what you mean. Can you post the output that you're seeing and the view in question?

-James

--
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...@googlegroups.com.
To post to this group, send email to django...@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/04067a15-d2cd-48d9-810c-8abe5760278c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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/7be9a742-26dc-4a85-b6c1-2ab6def4696f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
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/CAD4ANxWygm1g6KVvZTL005ZuQVLQLAPYRuWf0EXrU1kmviL6yg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment