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. www.example.com/admin or 127.0.0.1:8000/admin. One should prevent access to admin interface  to public or external users. Admin url should be changed from /admin to /some-other-url which is difficult to guess. admin is just another app like welcome or example app, so changing appliacation name will change url to it.

For example to change admin  to w2p-adm2in  do following steps

1. Rename admin folder with w2p-adm2in
On linux

On Windows

If you are in local environment, you can also do it using your file explorer

2. Fix broken links
Due to changes done in Step 1, links to admin app are broken. Links to admin app needs to be replaced with links to w2p-adm2in.

In app_name/controllers/appadmin.py
Update response.menu, change it to following

3. Instead of admin app, check user is logged in to w2p-adm2in app
while accessing appadmin, by default controller app_name/controllers/appadmin.py checks whether user is logged in to admin app or not, if not then it redirects to admin app(admin app login page), now it should check whether user is logged in to w2p-adm2in app and if not it should redirect to w2p-adm2in. To acheive this, pass other_application='w2p-adm2in'  as parameter to method gluon.fileutils.check_credentials()

After step 2 and step 3, diff file of app_name/controllers/appadmin.py will look like following

4. Change links to error page (tickets)
By default links to error is /admin/default/ticket/[ticket_id], Now it should be /w2p-adm2in/default/ticket/[ticket_id]
So add/replace/append following lines to web2py/routes.py

If routes.py file does not exist in web2py folder then create it containing above lines.

 

If you more changes that needs to be done, please comment below.

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

In this article, I will explain built in validator [crayon-58490fe64e8bc561819330-i/]  and [crayon-58490fe64e8c2554732354-i/], also a custom validator. It is important to validate file uploaded on server to restrict malicious files like .py .php, … [Continue reading]

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 [crayon-58490fe64ec4c237902657-i/] or [crayon-58490fe64ec53848267167-i/] example: … [Continue reading]

How to password protect PDF file using Python?

We will use python library PyPDF2 to set password to pdf file. To install PyPDF2: [crayon-58490fe64eecc297923837/] We are using encrypt function of PyPDF2. encrypt(user_password, owner_password=None, use_128bit=True) user_password  – The … [Continue reading]

Memory profiling in Python using memory_profiler

To install memory_profiler: [crayon-58490fe64f10a803288263/] Profile function/script: Add following line in script to import memory profiler: [crayon-58490fe64f10f566913113/] Decorate the function you would like to profile with … [Continue reading]

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 … [Continue reading]

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 … [Continue reading]

Size Contest (SPOJ Challenge problem 378)

Given the set of integers, find the sum of all positive integers in it. Solutions can be sent in any language supported by SPOJ except Whitespace. Input t – number of test cases [t < 1000] On each of next t lines given a integer N [-1000 <= … [Continue reading]

Factorial (SPOJ problem 11)

View problem on SPOJ The most important part of a GSM network is so called Base Transceiver Station (BTS). These transceivers form the areas called cells (this term gave the name to the cellular phone) and every phone connects to the BTS with the … [Continue reading]

Check whether one string is rotated version of other(Josh software programming test problem-2)

Write a program to accept two strings str1 and str2 and checks whether str2 is rotated version of str1. Ex. Following are different values of str2 for given str1. GIVEN:str1="software" 2-character left rotate str2='resoft' 4-character left … [Continue reading]