New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
multiple route and one function work random,404 #153
Comments
Hi @alingse, I'm sorry but right now multiple route decorations are not supported. The current weppy wants you to write something like this (is ugly, I know): def book(isbn=None,bookid=None):
# code returning data
@app.route('/api/v1/book/isbn/<str:isbn>')
@service.json
def book_wisbn(isbn):
return book(isbn=isbn)
@app.route('/api/v1/book/<int:bookid>')
@service.json
def book_wid(bookid):
return book(bookid=bookid) |
Hi @gi0baro , I have just test the package post by @hydeparkk ,his weppy works well. and I do some test on latest weppy(0.7.8) ....
@app.route('/api/v1/book/isbn/<str:isbn>')
@app.route('/api/v1/book/<int:bookid>')
#@service.json
def book(isbn=None,bookid=None):
if True:
return str([bookid,isbn])
... It also works well, I try say more thing about my first code if random.random()>0.5:
#return 1
return isbn
#return 2
....
return data just go into I think something wrong while the code going to |
@alingse please use the code I given to test your code. It probably goes to 404 because it's searching for a template since you don't have the json service anymore. |
Yes, @gi0baro , And Inspired by your code and the comment test 1. @app.route('/api/v1/book/isbn/<str:isbn>')
@service.json
@app.route('/api/v1/book/<int:bookid>')
@service.json
def book(isbn=None,bookid=None):
return [isbn,bookid] http://127.0.0.1:8001/api/v1/book/isbn/1231 --> ["1231", null] test 2. @app.route('/api/v1/book/isbn/<str:isbn>')
@app.route('/api/v1/book/<int:bookid>')
@service.json
def book(isbn=None,bookid=None):
return {'isbn':isbn,'bookid':bookid} http://127.0.0.1:8001/api/v1/book/isbn/1231 --> 404 test 3. @app.route('/api/v1/book/isbn/<str:isbn>')
@app.route('/api/v1/book/<int:bookid>')
@service.json
def book(isbn=None,bookid=None):
return [isbn,bookid,isbn,bookid] http://127.0.0.1:8001/api/v1/book/isbn/1231 --> 12311231 the python‘s decorator order or different serializers might was the reason I choose to use twice Thank you && Thank @hydeparkk too. |
@alingse thank you for sharing your experiments. Will keep this open until complete support for multiple routes is implemented so I can update you about the status. There's no official ETA, but probably will be included in weppy 1.0, scheduled for the end of the year/start of the next year. |
@alingse I have an update on this. @app.route(['/api/v1/book/isbn/<str:isbn>', '/api/v1/book/<int:bookid>'])
@service.json
def book(isbn=None,bookid=None):
# code When you need to build reverse routing with the >>> url('book', 'fe23')
/api/v1/book/isbn/fe23 if you need anyone of the other paths, you can use an underscore notation with the position in the array: >>> url('book_1', 123)
/api/v1/book/123 @alingse I would love to hear your feedback on this. If you are satisfied with the solution, I'm gonna close this and update the docs for the 1.0 |
nice , this can be closed
and yet I have two advice about |
@alingse ok, I'm closing this. |
Here is my simple app server,use two route
/api/v1/book/isbn/<str:isbn>
and/api/v1/book/<int:bookid>
when I visit
http://127.0.0.1:8001/api/v1/book/isbn/1231
It works 50% work at
#return 1
,50% 404,I dont know why,It has run inside the book function already。
This is my code:
The text was updated successfully, but these errors were encountered: