Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Opether_Maro
    @OpetherMB
    i tried @app.route("/push", methods=['POST'])
    with single quote on POST
    and it did not work
    Adam Hopkins
    @ahopkins
    single or double should not matter
    Opether_Maro
    @OpetherMB
    what so wrong with single quote around POST that it did not work
    no it did not
    Adam Hopkins
    @ahopkins
    in the /client handler, I see the methods param in the handler definition and not the decorator
    Opether_Maro
    @OpetherMB
    Exactly
    that was the error
    Adam Hopkins
    @ahopkins
    all good?
    Opether_Maro
    @OpetherMB
    Everything is good
    thank you alot
    Adam Hopkins
    @ahopkins
    :+1: Happy to help
    good luck
    Neil Chudleigh
    @nchudleigh
    Hey not sure if this is the right spot for this, but wondering if there are proper typing stubs for sanic
    Trying to start a new project out on the right foot- and noticed there is a py.typed file, but am not getting type information in pylance or mypy
    Adam Hopkins
    @ahopkins
    The older parts of the codebase have been missing typing information for a while
    I am working on this PR to resolve that.
    It will be in 21.3
    Neil Chudleigh
    @nchudleigh
    Awesome, thanks for the insight- is there anything we can do in the community to help with this?
    For example if I opened a PR adding types for some of the old code, would it be considered? Or is it something you would prefer to handle personally?
    Happy to kick in a few files 🤘
    Adam Hopkins
    @ahopkins
    I am ALWAYS happy to have help from the community.
    Callum
    @howzitcal

    Hey :)

    I've just stumbled onto Sanic, and I want to build class views similar pyramid eg:

    @route('/user/<username>')
    class UserView(ClassViewParent):
        def set_context(self, username):
            self.request.user = ORM.objects.get_or_404(username=username)
    
        @app.route("/", methods=["GET"])
        def show_profile(self):
            # here we have access to self.request and self.context which is the user object
            # show the user profile
    
        @app.route("/", methods=["PUT"])
        def update_user(self):
            # here we have access to self.request and self.context which is the user object
    
        @app.route("/delete", methods=["GET"])
        def delete_user_confirm(self):
            # here we have access to self.request and self.context which is the user object
            # sends user to confirm page to delete account
    
        @app.route("/delete", methods=["DELETE"])
        def delete_user(self):
            # here we have access to self.request and self.context which is the user object
            # deletes account

    should I be creating a considering creating my own class that does this?
    am I wrong to want todo things this way?
    can you suggest a better way or perhaps code that is already out there that I should try?

    I have created this class type view in flask before, however I remember is not being as awesome as I wanted it to be

    Adam Hopkins
    @ahopkins
    If you have other questions on how to implement something similar feel free to post here or start a thread on the forums
    Callum
    @howzitcal
    Thanks @ahopkins, as far as I can see the ClassViews only allow you to add get, port, put, etc methods to that class, where I am looking for more of a functional view encased in a class. I'm not sure if my idea is a bad idea, perhaps I am looking for something between a mix of Class Views and Blueprints
    Adam Hopkins
    @ahopkins
    I posted an example and my response here:
    https://community.sanicframework.org/t/example-nesting/791
    Easier for someone else with a similar question to find it in the future
    Callum
    @howzitcal
    @ahopkins are you superhuman?
    sorry will use the forum more :)
    Adam Hopkins
    @ahopkins
    Chat is fine
    But with a more involved answer I'd rather the example not get lost in the ether of chat history
    Callum
    @howzitcal
    makes sense going through your post now @ahopkins
    Adam Hopkins
    @ahopkins
    :+1:
    Opether_Maro
    @OpetherMB
    hey guys i hope you are doing good, i have a simple question i have a rout(/exportcsv), and i want to send data as csv, knowing that this data is encoded as a json obj in redis and i am going to convert it to a csv file and return as response, i read that i have to use probably file streams ..can qomeone please elaborate ? or give an example ... thank you alot
    Opether_Maro
    @OpetherMB
    def .....
    ...
    ..
    # Function you need to defien for file streaming
        async def streaming_fn(response):
    
            data = io.StringIO()
            cw = csv.writer(data)
    
            for row in [flatten_json.keys(),flatten_json.values()]:
                cw.writerow(row)
    
            await response.write(data.getvalue())
    
        content_type = 'text/csv'
    
        return response.stream(
                streaming_fn,
                content_type=content_type,
                headers={
                    'Content-Disposition': 'attachment; filename="file-{}.csv";'.format(
                        arrow.utcnow().format('YYYY-MM-DD-HH-MM-SS')
                    ),
                    'Content-Type': content_type,
                }
            )
    i found a solution for this in case anyone looking for how to do it ...have a great day guys
    Adam Hopkins
    @ahopkins
    🤘
    tris-tan
    @tris-tan
    @ahopkins I'm trying to adapt the code you posted https://community.sanicframework.org/t/how-to-use-asyncio-queues-in-sanic/166/3 for my purposes but python is convinced the checker handler function is a tuple if i try to call it, for some reason?
    tris-tan
    @tris-tan
    If I remove the @app.get("/") decorator it works as it should
    Adam Hopkins
    @ahopkins
    without the decorator it doesn't get regosrerest
    have you modified the code?
    *registered
    Opether_Maro
    @OpetherMB
    hey everyone ..i am running a sanic app in a container and it is connecting to redis also running into another container via docker-compose everything was working fine until the app droke, here are some logs :
    image.png
    do you have guys any idea hy would the server stopped ?
    thanks in advance i can show you m code in case
    Adam Hopkins
    @ahopkins
    This is no longer a maintained support channel. Please use the forums or the doscord server.