Thank you. But I want to fix it like this, because the time of "do something" is not long. #######################################
from django.http import HttpResponseimport datetimedef current_datetime(request): now = datetime.datetime.now() if now == 2013: html = "<html><body>It is now %s.</body></html>" % now return HttpResponse(html) else: # giva a response first urllib.urlopen(message) # do something print 'not 2013' sys.exit(0) ####################################### 2013/6/25 Hector Armando Vela Santos <vello...@gmail.com> > You can use Celery for that, I've done something similar, just with a CSV > instead of a XML, check this > http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html > > once installed and configured, its as simple as: > > from celery import task > > if (the xml format is ERROR) == True: > return HttpResponse(<html><body>ERROR FORMAT</body></html>") > else: > do_something.delay(the_xml_file) > return HttpResponse(<html><body>RIGHT FORMAT</body></html>") > #I must give a response first, And do other thing. Because the spend > time of do_something() may be long. > > @task(ignore_result=True) > def do_something(xml): > #do something time consuming > > > and the do_something function will be called in second plane, and the user > will get an instant response, even if the parsing file process takes half > an hour > > > On Tuesday, June 25, 2013 8:32:59 AM UTC-5, lx wrote: > >> Thank you. >> >> The real demand is: >> >> 1. >> receive the xml file from client. >> >> 2. >> if (the xml format is ERROR) == True: >> return HttpResponse(<html><body>ERROR FORMAT</body></html>") >> else: >> return HttpResponse(<html><body>RIGHT FORMAT</body></html>") >> #I must give a response first, And do other thing. Because the spend >> time of do_something() may be long. >> do_something(the xml file) >> >> >> >> >> >> >> 2013/6/25 Sandro Dutra <hex...@gmail.com> >> >>> The question is: What you're trying to do? >>> >>> 1. You can do any other process before the return line, the return will >>> be the same... for example: >>> >>> from django.http import HttpResponse >>> from datetime import datetime >>> def current_datetime(request): >>> now = datetime.now() >>> html = "<html><body>It is now %s.</body></html>" % now >>> year = now.year() >>> return HttpResponse(html) >>> >>> >>> 2. You can use a conditional to have multiple returns: >>> from django.http import HttpResponse >>> from datetime import datetime >>> def current_datetime(request): >>> now = datetime.now() >>> html = "<html><body>It is now %s.</body></html>" % now >>> year = now.year() >>> if year == 2013: >>> return HttpResponse(html) >>> else: >>> return HttpResponse(<html><body>Sorry it's not >>> 2013.</body></html>") >>> >>> >>> 2013/6/25 Timster <timsha...@gmail.com> >>> >>>> You cannot do something after the "return" line. This is Python >>>> functionality. When you return, the function exits and does not process >>>> anything else. >>>> >>>> What exactly are you trying to do? There is probably another way to >>>> accomplish it. >>>> >>>> -- >>>> 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 >>>> http://groups.google.com/**group/django-users<http://groups.google.com/group/django-users> >>>> . >>>> For more options, visit >>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>>> . >>>> >>>> >>>> >>> >>> -- >>> 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 >>> http://groups.google.com/**group/django-users<http://groups.google.com/group/django-users> >>> . >>> For more options, visit >>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >>> . >>> >>> >>> >> >> -- > 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. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- 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. For more options, visit https://groups.google.com/groups/opt_out.