Search code examples
c#asp.netpythondjangorunatserver

Capturing/Logging image related data using Django/Python


I come from a ASP.Net background and taking baby steps in open source world. I have an image based application and for every image click I want to log data on server. I'm using Django/Python to host this application.

My understanding is that I need to process this data on client side and send to server using Ajax calls. Please correct me if I'm wrong. In ASP.net world, we had "runat=server" tag for every HTML control that made logging data on server really easy. Is there something similar in Django/Python?

Also, what is the most efficient way of logging image data in this situation?

Thanks in advance. Your help is highly appreciated.

Cheers!!


Solution

  • Your understanding of needing to use AJAX calls is one correct answer.

    You could also register onclick JavaScript events for all images and have the JavaScript call a function that submits a form with the needed values for the view to process. That's sort of how ASP.net's PostBack works. The only difference is you're writing the client-side code yourself and nothing is obfuscated with the __VIEWSTATE hidden field.

    Basically, ASP.net and Django come from two very different schools of thought. ASP.net's runat=server stuff makes things accessible to the various Page Lifecycle Events (Init, PreLoad, Render, etc) using helpful nuggets from __VIEWSTATE.

    Django has no such Page Lifecycle model. It keeps things much simpler: a request is directed to a view method (or class-based view) using urls.py. The view method then returns a response.

    There are benefits and drawbacks to both ways of doing things.

    The short answer is that different frameworks tend to solve the same problem in different ways.