Houdini 19.0 hwebserver

hwebserver.Request class

A request made to Houdini’s web server.

On this page

Note

This class is accessible using both hwebserver.WebServerRequest and hwebserver.Request, but hwebserver.Request is preferable.

This object is passed to your registered URL handler function as a container for information from the client request.

Upload example

import tempfile
import hwebserver
import hou


@hwebserver.urlHandler("/blur_image")
def blur_image(request):
    if request.method() == "GET":
        return hwebserver.Response('''
            <p>Upload an image</p>
            <form method="POST" enctype="multipart/form-data">
                <input type="file" name="image_file">
                <input type="submit">
            </form>
        ''')

    if request.method() != "POST":
        return hwebserver.notFoundResponse(request)

    image_file = request.files().get("image_file")
    if image_file is None:
        return hwebserver.errorResponse(request, "No image was posted", 422)
    image_file.saveToDisk()

    # Use a COP network to load the image, blur it, and write it to a
    # temporary output file.
    copnet = hou.node("/img").createNode("img")
    file_cop = copnet.createNode("file")
    file_cop.parm("filename1").set(image_file.temporaryFilePath())

    blur_cop = copnet.createNode("blur")
    blur_cop.setFirstInput(file_cop)
    blur_cop.parm("blursize").set(10)

    rop = copnet.createNode("rop_comp")
    rop.setFirstInput(blur_cop)
    rop.parmTuple("f").set((1, 1, 1))
    temp_output_file = tempfile.mkstemp(".jpg")[1]
    rop.parm("copoutput").set(temp_output_file)
    rop.render()

    copnet.destroy()

    return hwebserver.fileResponse(temp_output_file, delete_file=True)


hwebserver.run(8008, True)

Methods

hwebserver

クラス

開始と停止

ウェブリクエストの処理とレスポンスの返し

ウェブソケット

  • WebSocket

    Base class for WebSocket support with the embedded server.

  • hwebserver.webSocket

    Decorator for registering WebSocket classes with Houdini’s web server.

APIコール

  • hwebserver.apiFunction

    Decorator for functions that can be called through an API endpoint on Houdini’s web server, returning JSON or binary responses.

  • hwebserver.APIError

    Raise this exception in apiFunction handlers to indicate an error.