Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] URL path recognition error when get request comes first and post request comes later #1200

Open
lijwchn opened this issue Jun 21, 2024 · 0 comments

Comments

@lijwchn
Copy link

lijwchn commented Jun 21, 2024

Describe the bug
A clear and concise description of what the bug is.

Versions (please complete the following information):

  • Python version: [3.11]
  • Django version: [django==4.2.13]
  • Django-Ninja version: [django-ninja==1.1.0]

hi,vitalik
Thank you very much for this great project

this is my code in api.py

@router.get("/employees/{employee_id}", response=EmployeeOut, description="根据id获取员工信息")
def get_employee_by_id(request, employee_id: int):
employee_instance = get_object_or_404(Employee, id=employee_id)
return standard_response(data=employee_instance)

@router.post("/employees/create")
def create_employee(request, payload: EmployeeIn):
employee = Employee.objects.create(**payload.dict())
return standard_response(data=employee.id)
When I requested the interface "/employees/create" using Postman, it prompted "method not allowed". I started debugging the code and found that in this case, the post interface would recognize "/create" as "{employee_id}" in the get interface, resulting in this error prompt

image

Although this bug can be easily avoided, I hope to receive your advice. I am a Python beginner, haha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant