How to assign python variable to Javascript variable in web2py

You might be using following statement to assign python variable to javascript variable on older versions of web2py (<2.9.11), may be because of this question on stackoverflow: var javascript_array = {{=XML(response.json(array))}} 1 var javascript_array =  {{=XML(response.json(array))}} Above statement was working… Read the rest

How to change admin app url in web2py?

This question was asked here How to rename “/admin” to other URL in web2py? For all the web2py applications, web2py admin url is same, i. e. or One should prevent access to admin interface  to public or… Read the rest

How to do file validation in web2py and write custom validator to validate files?

In this article, I will explain built in validator IS_IMAGE  and  IS_UPLOAD_FILENAME, also a custom validator. It is important to validate file uploaded on server to restrict malicious files like .py .php, .exe bat etc. Web2py provides 2 validators to… Read the rest

How to write custom download controller in web2py?

Suppose we have employee table with resume as uplaod field. And we want to download file on the basis of employee id. Download  url is like app_name/custom_download/employee_id or <a href="{{=URL('default', 'custom_download', args = employee_id)}}" download> example: Consider following employee… Read the rest

How to password protect PDF file using Python?

We will use python library PyPDF2 to set password to pdf file. To install PyPDF2: sudo pip install pypdf2 1 sudo pip install pypdf2 We are using encrypt function of PyPDF2. encrypt(user_password, owner_password=None, use_128bit=True)
  • user_password  – The “user password” allows
Read the rest

Memory profiling in Python using memory_profiler

To install memory_profiler: sudo easy_install -U memory_profiler 1 sudo easy_install -U memory_profiler
  • Profile function/script: Add following line in script to import memory profiler: from memory_profiler import profile 1 from memory_profiler import profile Decorate the function you would like to profile
  • Read the rest

    Time profiling in python using cProfile

    In this article we will cover following points:
  •  Profile single function
  • Profile complete python script
  • How to read .prof file
  • Profile web2py application
  • To install cprofile on ubuntu use following command: sudo pip install cprofilev 1 sudo pip install cprofilev… Read the rest

    How to measure performance of code ? – Basic methods

    In this article, we will cover some very basic methods to calculate performance of script. In next article we will cover advance tool like cProfile and memory_profiler. What is profiling?
    • Profiling is program analysis that measures, for example, the space
    Read the rest