Open DhiaTN opened 6 years ago
What is your output of
for rule in app.url_map.iter_rules():
print(rule)
?
I found out the issue but could not understand why it's causing the problem. Let's say I have the following structure:
|-- project/
| |-- service/
| | |-- __init__.py
| | |-- api.py
| | |-- models.py
....
if namespace is defined in the api.py
file and then imported from there to be added to the api, it works just fine, but if the namespace is created in __init__.py
and used in the api.py
the same way the endpoints are not registered if you add the namespace to the api.
share a full code sample @DhiaTN
I faced the same issue, I have solved it by importing app from the same file where I am defining (registering) endpoints. just writing it for someone will come here facing the same issue in future :)
@singh-harveer thanks, your idea saved me :)
Just import the controller file (file containing endpoints) in your init.py. It will work !!
@singh-harveer - How did you actually do that? I am using blueprints and all of them are registered using api.register_blueprint() function. I imported the app directly from there with no success. Always getting 404!
Hi @moawiah It has been quite a time, since i have posted this. have a look on this python snippet here
Idea is to import Api, and Resource in same file where you are registering the endpoints. like:
from flask_restplus import Api, Resource
Hope it help you.
PS: Above shared snippet is quite old, so there might lot have changed in flask-restplus
.
Thanks for the quick response! I am using flask smorest and facing same issue! I am already importing Api in the same file registering the blueprints
api.register_blueprint(basic_analytics_bp)
I'm testing my flask app using pytest, when it comes to test the enpoints I used the Flask
app.test_client
utility:Trying the test the endpoints as follow:
But I get always
<Response streamed [404 NOT FOUND]>
when I test it against endpoint registered from restplusNamespace
:but works fine if the endpoint is registered using
app.add_url_rule
. It seems like an issue (#356 ) have been also reported in the past but not solved.I'm using
pytest (3.4.1)
,Flask (0.12.2)
,flask-restplus (0.10.1)
on OSX environment.