Skip to content

Commit 3296664

Browse files
authored
Update automating-word-documents.md
1 parent 050ab27 commit 3296664

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/pages/blog/automating-word-documents.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ After creating and activating the virtual environment, **install** required **li
6868
pip install "fastapi[standard]" docx docxtpl pydantic requests
6969

7070
Then, Create a file “**main.py”** with:
71-
71+
```python
7272
from fastapi import FastAPI
7373

7474
app = FastAPI()
@@ -77,21 +77,21 @@ Then, Create a file “**main.py”** with:
7777
@app.get("/")
7878
def read_root():
7979
return {"Hello": "World"}
80-
80+
```
8181
If you make a **request** (using Postman, or your browser) to ***“localhost:8000”***, you should get this as the output:
82-
82+
```python
8383
{
8484
"Hello": "World"
8585
}
86-
86+
```
8787
Now that we have a basic endpoint running, we can start rendering context into Word template file.
8888

8989
Import your **Jinja2** modified Word template file into the root of your project like so:
9090

9191
![](https://cdn-images-1.medium.com/max/2000/1*IBOIVtjqQ2i1lCoRI9d1aQ.png)
9292

9393
Modify the main.py file to be:
94-
94+
```python
9595
from fastapi import FastAPI
9696
from docxtpl import DocxTemplate, InlineImage
9797
from pydantic import BaseModel
@@ -198,7 +198,7 @@ Modify the main.py file to be:
198198
return StreamingResponse(result,
199199
media_type="application/vnd.openxmlformats-officedocument.wordprocessingml.document",
200200
headers={"Content-Disposition": "attachment; filename=invoice.docx"})
201-
201+
```
202202
Now, let’s test the endpoint by sending a **JSON body** and **retrieve** the **generated output**.
203203

204204
{

0 commit comments

Comments
 (0)