Thursday, 15 August 2013

converting Python code to Django framework -



converting Python code to Django framework -

i have standalone application on desktop written in python. using modules tkinter, cv2, numpy in application. tkinter renders gui (which has button , image). issue want create web application. purpose, using django framework asks segregate model ,view , template(mtv) . how render same gui same buttons , images using html. (my gui having buttons , image should in template while business logic should in view.) piece of code want convert mtv form. want upload button in template(html). onclick of upload button programme should go view(logic).how segregate logic , html? (is necessary? can convert entire thing django framework without segregating) please help.

def upload(): global original_img,img,img2,img3,image_path,old_label_image,photo,label,image_path,image,ax,fig print "upload" image_path=tkfiledialog.askopenfilename() image = image.open(image_path) original_img= image.copy() image.thumbnail((1000,625)) photo = imagetk.photoimage(image) label = label(image=photo) label.image = photo if old_label_image not none: old_label_image.destroy() old_label_image = label #label.update() label.pack() root = tk.tk() # creating instance of tk class print "main" old_label_image = none frame = frame(root) #creates new window (given pathname argument) , makes frame widget.the frame command returns path name of new window. frame.pack() #the pack geometry manager packs widgets in rows or columns bottomframe = frame(root) bottomframe.pack( side = bottom ) uploadbutton = button(frame, text="upload", command= upload) uploadbutton.pack( side = left) root.mainloop()

you can't "convert" code this. writing applications web different writing them desktop framework. you'll need think how nowadays form in html, how take uploaded file, how nowadays response user, , on. django has functionality of these, it's totally different way of doing things: 1 thing, initial presentation of form , returning of response done in separate requests, no persistence between them.

python django opencv

No comments:

Post a Comment