Python aiohttp motorengine
Я пытаюсь сделать базовый регистр api, но у меня проблемы с motorengine
а также aiohttp
.
Может кто-нибудь привести мне примеры того, как это работает?
Вот мой код:
from motorengine.connection import connect
from motorengine.document import Document
from motorengine.fields import StringField, DateTimeField
from aiohttp import web
import asyncio
import json
dbAdress = "mongodb+srv://test:Z1PKIdwMVNPA63Em@cluster0-0ehjt.mongodb.net/test?retryWrites=true&w=majority"
client = connect("test", dbAdress)
class Members(Document):
__collection__ = "Members"
name = StringField(required=True)
password = StringField(required=True)
register_date = DateTimeField(auto_now_on_insert=True)
async def index(request):
response = {"status": "success"}
return web.Response(text=json.dumps(response), status=200)
async def register(request):
print(1)
try:
data = await request.json()
print(data)
username = data['username']
password = data['password']
print(username)
if(username == "" or password == ""):
raise KeyError
print(Members.objects.filter(username=username))
return web.Response(status=200)
except KeyError:
return web.Response(status=401)
app = web.Application()
app.add_routes([web.get("/", index),
web.post("/register", register)])
web.run_app(app)