url-routing

FastAPI: How to get raw URL path from request?

FastAPI: How to get raw URL path from request? Question: I have a GET method with requested parameter in path: @router.get(‘/users/{user_id}’) async def get_user_from_string(user_id: str): return User(user_id) Is it possible to get base url raw path (i.e., ‘/users/{user_id}’) from the request? I have tried to use the following way: path = [route for route in …

Total answers: 5

Difference between reverse() and reverse_lazy() in Django

Difference between reverse() and reverse_lazy() in Django Question: I understand that we can use reverse() in FBV and reverse_lazy() in CBV. I understand that we have to use reverse_lazy() in CBV as the urls are not loaded when the file is imported (Ref: Reverse_lazy and URL Loading?) What I don’t understand is: How are the …

Total answers: 7

NoReverseMatch at /product/pussyes/ Reverse for 'basket_adding' not found. 'basket_adding' is not a valid view function or pattern name

NoReverseMatch at /product/pussyes/ Reverse for 'basket_adding' not found. 'basket_adding' is not a valid view function or pattern name Question: NoReverseMatch at /product/pussyes/ Reverse for ‘basket_adding’ not found. ‘basket_adding’ is not a valid view function or pattern name. Request Method: GET Request URL: http://127.0.0.1:8000/product/pussyes/ Django Version: 1.11 Exception Type: NoReverseMatch Exception Value: Reverse for ‘basket_adding’ not …

Total answers: 2

Flask and React routing

Flask and React routing Question: I’m building the Flask app with React, I ended up having a problem with routing. The backend is responsible to be an API, hence some routes look like: @app.route(‘/api/v1/do-something/’, methods=[“GET”]) def do_something(): return something() and the main route which leads to the React: @app.route(‘/’) def index(): return render_template(‘index.html’) I’m using …

Total answers: 5

Flask url_for generating http URL instead of https

Flask url_for generating http URL instead of https Question: I am using url_for to generate a redirect URL when a user has logged out: return redirect(url_for(‘.index’, _external=True)) However, when I changed the page to a https connection, the url_for still gives me http. I would like to explicitly ask url_for to add https at the …

Total answers: 7

Flask URL Route: Route Several URLs to the same function

Flask URL Route: Route Several URLs to the same function Question: I am working with Flask 0.9. Now I want to route three urls to the same function: /item/<int:appitemid> /item/<int:appitemid>/ /item/<int:appitemid>/<anything can be here> The <anything can be here> part will never be used in the function. I have to copy the same function twice …

Total answers: 2

Accessing Primary Key from URL in Django View Class

Accessing Primary Key from URL in Django View Class Question: I have a URL pattern mapped to a custom view class in my Django App, like so: url( r’^run/(?P<pk>d+)/$’, views.PerfRunView.as_view( )) The problem is, I cannot figure out how I can access ‘pk’ from the URL pattern string in my view class so that I …

Total answers: 4