eve

Servicing html requests with Eve

前提是你 提交于 2019-12-06 10:47:03
问题 I am attempting to build a MongoDB-backed Flask application which serves from the same endpoints: A HTML web interface by default A JSON response if Content-Type == application/json The idea is that both a user consuming my application with a browser and a service consuming my API programatically can both hit http://myapp.com/users/12345 The former is served a HTML response and the latter is served a JSON response. As I understand this is in keeping with 'pure' REST, in contrast to the

Python Eve - where clause using objectid

一世执手 提交于 2019-12-06 09:51:44
I have the following resource defined in settings.py, builds = { 'item_title': 'builds', 'schema': { 'sources': { 'type': 'list', 'schema': { 'type': 'objectid', 'data_relation': { 'resource': 'sources', 'embeddable': True, } } }, 'checkin_id': { 'type': 'string', 'required': True, 'minlength': 1, }, } } When I try to filter based on a member whose value is an objectid, I get empty list. http://127.0.0.1:5000/builds?where={"sources":"54e328ec537d3d20bbdf2ed5"} 54e328ec537d3d20bbdf2ed5 is the id of source Is there anyway to do this? Your query should work just fine assuming that you actually

can't search eve rest API - additional lookup not working

耗尽温柔 提交于 2019-12-06 09:44:37
I was following the example here: https://github.com/pyeve/eve-demo/blob/master/settings.py When I go to localhost:5000/apps, I can see all the documents in my collection, but when I search for an email at localhost:5000/apps/example@gmail.com, it says '404 not found'. I've confirmed the regex, and the email addresses are in the documents. Can anyone see what might be wrong? run.py from eve import Eve if __name__ == '__main__': app = Eve() app.run() settings.py: RESOURCE_METHODS = ['GET', 'POST', 'DELETE'] ITEM_METHODS = ['GET', 'PATCH', 'PUT', 'DELETE'] MONGO_HOST = 'localhost' MONGO_PORT =

Writing tests for Python Eve RESTful APIs against a real MongoDB

拈花ヽ惹草 提交于 2019-12-05 22:33:40
I am developing my API server with Python-eve, and would like to know how to test the API endpoints. A few things that I would like to test specifically: Validation of POST/PATCH requests Authentication of different endpoints Before_ and after_ hooks working property Returning correct JSON response Currently I am testing the app against a real MongoDB, and I can imagine the testing will take a long time to run once I have hundreds or thousands of tests to run. Mocking up stuff is another approach but I couldn't find tools that allow me to do that while keeping the tests as realistic as

Python Eve contains filter

为君一笑 提交于 2019-12-05 16:17:38
There's some way to return items that field contains some value? Eg. GET /people?contains="foo" Return all persons that have the word 'foo' in the name. Thanks in advance You could use mongodb $regex operator, which is blacklisted by default in Eve ( MONGO_QUERY_BLACKLIST = ['$where', '$regex'] ). Add MONGO_QUERY_BLACKLIST = ['$where'] to your settings.py . Then you can query your API like this: ?where={"name": {"$regex": ".*foo.*"}} . Be careful however. If you don't control the client, enabling regexes could potentially increase your API vulnerability. I am not conversant with Eve myself.

In Eve, how can you store the user's password securely?

旧时模样 提交于 2019-12-04 20:31:52
If you put a debugger in the run file, you will see that the user's password is hashed, but when you look in the mongo collection, the user's password is stored in plain text. How do you save the user's password as a hash? Here are my files: run.py: from eve import Eve from eve.auth import BasicAuth import bcrypt class BCryptAuth(BasicAuth): def check_auth(self, username, password, allowed_roles, resource, method): # use Eve's own db driver; no additional connections/resources are used accounts = app.data.driver.db["accounts"] account = accounts.find_one({"username": username}) return account

Servicing html requests with Eve

柔情痞子 提交于 2019-12-04 16:29:54
I am attempting to build a MongoDB-backed Flask application which serves from the same endpoints: A HTML web interface by default A JSON response if Content-Type == application/json The idea is that both a user consuming my application with a browser and a service consuming my API programatically can both hit http://myapp.com/users/12345 The former is served a HTML response and the latter is served a JSON response. As I understand this is in keeping with 'pure' REST, in contrast to the tradition of serving the API from a separate path such as http://myapp.com/api/users/12345 . There is no

eve app deployment errors can anyone help me to fix it

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: [Sat Apr 09 18:27:29.953008 2016] [:error] [pid 3230:tid 140635784853248] [client 103.14.196.22:53950] mod_wsgi (pid=3230): Target WSGI script '/var/www/FlaskApps/FlaskApps.wsgi' cannot be loaded as Python module. [Sat Apr 09 18:27:29.953045 2016] [:error] [pid 3230:tid 140635784853248] [client 103.14.196.22:53950] mod_wsgi (pid=3230): Exception occurred processing WSGI script '/var/www/FlaskApps/FlaskApps.wsgi'. [Sat Apr 09 18:27:29.953065 2016] [:error] [pid 3230:tid 140635784853248] [client 103.14.196.22:53950] Traceback (most recent call

jquery stop child triggering parent event

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a div which I have attached an onclick event to. in this div there is a tag with a link. When I click the link the onclick event from the div is also triggered. How can i disable this so that if the link is clicked on the div onclick is not fired? script: $(document).ready(function(){ $(".header").bind("click", function(){ $(this).children(".children").toggle(); }); }) html code: some link some list 回答1: Do this: $(document).ready(function(){ $(".header").click(function(){ $(this).children(".children").toggle(); }); $(".header a")

EVE - define custom flask controllers [closed]

匿名 (未验证) 提交于 2019-12-03 01:12:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using EVE for couple of days to create my own REST API but I want to have custom Flask Controller integrated with EVE is there any possibility to do this? Thanks. 回答1: Ok I will answer my own question. After reading more about Eve, you can use any of Flask's methods because Eve is simply inheriting from the Flask class. For example, you can do this: from eve import Eve app = Eve() @app.route("/x") def hello(): return "Hello World!" if __name__ == '__main__': app.run(debug=True) There's more info at the Flask documentation site here: