routes

Python Flask distinct two generics routes

Python Flask distinct two generics routes Question: In python flask I have two routes with approximately the same behaviour to redirect on another service. The first one is to redirect a generic request to another API. @app.route(‘/factory/<path:url>’, methods=[‘GET’, ‘POST’, ‘PUT’, ‘DELETE’]) @cross_origin() def request_factory(url: str): resp = manage_factory_message(request) return app.response_class( response=resp.content, mimetype=resp.headers[‘Content-Type’], status=resp.status_code ) And …

Total answers: 1

How to hook up DRF ModelViewset to the app's root

How to hook up DRF ModelViewset to the app's root Question: I have a small django app with a single ViewSet that extends DRF’s ModelViewSet. I’ve tried attaching it to the app’s root url like so urlpatterns = [ path(r"", NotificationViewSet.as_view(), name="company"), ] But this is causing an error: TypeError: The actions argument must be …

Total answers: 1

React – Django page is blank on refresh

React – Django page is blank on refresh Question: Hello I am using Django as my backend and React as frontend. I have an issue when I refresh page and I am not on root page ‘/’ the page goes blank. Also If Ill try to go instantly somewhere else then the home page such …

Total answers: 2

bottle + CGI always matches / route

bottle + CGI always matches / route Question: I can’t get bottle to match any other route than “/” when deploying in a CGI environment. (I’m stuck with the hosting provider, FastCGI or WSGI are not on offer, unfortunately). Bottle lives in a subdirectory lib – I have dropped the bottle.py from bottle-0.12.18.tar.gz there. Python …

Total answers: 2

Flask middleware for specific route

Flask middleware for specific route Question: I made API Server with Python Flask-RESTful. My system use token authentication for verify permission. So, I added middleware for verify token. For example, code like this, [middleware.py] class Test(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): print("gogo") return self.app(environ, start_response) [app.py] from flask import Flask …

Total answers: 1

route flask from scheduled function

route flask from scheduled function Question: I have a Flask app, which is running a web-app to control an alarm. I use apscheduler to trigger a function triggerAlarm() and within that I want to have the logic to actually trigger it, but also I want to have the web-page to display another alarm.html, no matter …

Total answers: 1

Flask route giving 404 with floating point numbers in the URL

Flask route giving 404 with floating point numbers in the URL Question: I have the following route definition in my Flask app’s server.py: @app.route(‘/nearby/<float:lat>/<float:long>’) def nearby(lat, long): for truck in db.trucks.find({‘loc’: {‘$near’: [lat, long]}}).limit(5): if truck.has_key(‘loc’): del truck[‘loc’] return json.dumps(trucks) But when I go to http://localhost:5000/nearby/37.7909470419234/-122.398633589404, I get a 404. The other routes work fine, …

Total answers: 3

Add a prefix to all Flask routes

Add a prefix to all Flask routes Question: I have a prefix that I want to add to every route. Right now I add a constant to the route at every definition. Is there a way to do this automatically? PREFIX = “/abc/123” @app.route(PREFIX + “/”) def index_page(): return “This is a website about burritos” …

Total answers: 13