【发布时间】:2020-12-04 09:39:53
【问题描述】:
我只想用 DRF 制作一个简单的 API。 API 将从 URL 中获取一个“关键字”,并且该“关键字”将转到一个函数。函数响应将是 API 响应。
简单示例:
def returnSomething(word):
test_string = "This is a example sentence. "
add_string = word
test_string += add_string
return test_string
http://127.0.0.1:8000/api/langdetect/helloworld/
结果:
{
response: This is a example sentence. helloworld
}
一切都很简单。我怎样才能做到这一点?我阅读了文档,但每个示例都是使用模型、序列化程序等制作的。我没有任何模型。我只有一个函数和响应数据。
谢谢。
【问题讨论】:
-
@ArakkalAbu OP 想要使用 DRF,而不是裸 Django。
标签: python django django-rest-framework