Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
9367 Widoki

I have a requirement which i have to call same controller but i need to change controller type["HTTP", "JSON"] based on condition
here is controller definition

@http.route('/controller', auth="public")
Now the problem is i have to call same controller based on the request type send to my controller, like this
if it send request to '/controller' of type "HTTP" then dynamicallythis controller should become
 @http.route('/controller', auth="public", type="http")
and if it send request to '/controller' of type "JSON" then dynamically this controller should become
@http.route('/controller', auth="public", type="json")
i have tried writing controller like this
class my_controller(http.Controller)
     __dynamicallyType= None
     @http.route('/controller', auth="public", type= __dynamicallyType)

i can change variable "__dynamicallyTypefrom" another function before this controller is about to call ans i can see "__dynamicallyTypefrom" value change during runtime but the controller is not able to change its type dynamically, it assume to be change whatever i assign for first time, once the value is passed to the type of the controller then type of the controller do not change for next run
Any hint or trick or hack if fine

Awatar
Odrzuć
Najlepsza odpowiedź

IMHO, not possible...


What you can try, use 2 controllers which call common method...


    @http.route('/http', type='http', auth="none")    
def xhttp(self):
        return self.xmagic()

    @http.route('/json', type='json', auth="none")
def xjson(self):
        return self.xmagic(reqtype='json')

    def xmagic(self, reqtype='http'):
        l = ['a','b','c']
 if reqtype == 'http':
            return str(l)
else:
            return l


That will return:

    

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
paź 24
2844
1
paź 22
6460
1
lis 17
9979
6
gru 23
20164
3
mar 17
3947