Monday, January 2, 2012

technique about using thread in views.py

Hi,guys~
Happy new year ^^
I am a beginner at django.
I want to run a very simple thread in django project.
when view.py after running welcome_page.html to show a html on browser
then call a thread print something on background.
But I can't run it well with those two merged in views.py.
Following is the code I used.
What's wrong with my code....
Any tips?
Thanks.

Kay
-----------------------------------------------------------------------------------
from django.http import HttpResponse
from django.shortcuts import render_to_response
from django.core.context_processors import csrf
from threading import Thread

def welcome(request):
c = {}
c.update(csrf(request))
return render_to_response("welcome_page.html",c)

go = test()
go.start()

class test(Thread):

def __init__(self):
Thread.__init__(self)

def run(self):
print 'thread is running'

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

No comments:

Post a Comment