pythonhtmlwebparameter-passingfastapi

I have a problem with the parameters in fastapi


I have this application in fastapi. through a get request the page and area2 parameters are passed, the page parameter is correctly captured but the area2 is not, it returns none

@router.get("/")
async def home(request: Request, db: Session = Depends(get_db), page:int= 1, area2: str=None):
  print(page, area2)
  ...

This is my html

<span class="step-links"  >
    {% if page_obj.has_previous %}
        <a href="?page=1?&area2={{area}}">&laquo; first</a>
        <a href="?page={{ page_obj.number-1}}&?area={{area}}">  --previous  </a>
    {% endif %}

Solution

  • It is only necessary to put a single "?" for variables

     <span class="step-links"  >
        {% if page_obj.has_previous %}
            <a href="?page=1?area2={{area}}">&laquo; first</a>
            <a href="?page={{ page_obj.number-1}}?area={{area}}">  --previous  </a>
        {% endif %}