【发布时间】:2021-08-02 13:06:59
【问题描述】:
我有一个 django 项目。我想使用 JSON 文件获取站点信息和设置(例如电话号码 | 关于文本 | 联系我们信息)。
像这样--->
{
"about_text": "Hi this is about text",
"phone": "0912------984",
"email": "text@text.com"
}
并在视图中使用这些...
import json
from django.shortcuts import render
def about(request):
with open("data_file.json") as f:
data = json.load(f)
context = {
"about_us_text": data['about_text'] # Using *marked* lib to render to html (In template)
}
return render(request, 'about.html', context)
-
正确吗?解决方案不是最好的吗?它不会导致 有问题吗?
-
我认为有更好的解决方案,因为这可能需要时间和 放慢程序... .
【问题讨论】:
标签: python json django django-views django-templates