![]() While we have the structure of the function well understood, we have some work to do to send the SMS and to return a response, so we’ll continue working on this endpoint in the following sections. FastAPI will parse the form data and extract the value of this field passed by the client and send it to the function in this argument. The web form that we are using has a single field named phone, so we have that as an argument into the function. On this second endpoint we are using the decorator to define a handler for POST requests. You can add it at the bottom of app.py, but note the lines that start with # TODO, which indicate parts of the function that haven’t been built yet. The endpoint will have the following structure. This means that the form will be submitted with a POST request to the originating URL, which in this case is the root URL of the application. If you look at the element in index.html, we have defined the form with the method attribute set to post and no action attribute. This is because we have not implemented the form submission endpoint yet. If you try to submit the form, FastAPI will return a “Method not allowed” error message. The browser should load the main page of the application, which looks like this: To make sure that your application is correct, you can open a web browser and type in the address bar. You can leave the server running throughout the rest of the tutorial. We are starting the server with the -reload option, which will make uvicorn watch our source files and automatically restart the server when changes are made. Uvicorn is the recommended server to run FastAPI applications. env (note the leading dot) in your text editor and enter the following contents in it: The most secure way to define these configuration values is to set environment variables for them, and the most convenient way to manage your environment variables in a FastAPI application is to use a. ![]() Also, to send an SMS, you will need to provide a number for the sender, the Twilio number you purchased earlier. To be able to send an SMS with Twilio, the FastAPI application will need to have access to your Twilio account credentials to authenticate. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |