2,619
次編輯
Tankianting(討論 | 貢獻) |
Tankianting(討論 | 貢獻) |
||
行 21: | 行 21: | ||
] | ] | ||
</pre> | </pre> | ||
==view.py== | |||
假設要做 activitypub 協定,回傳 json 的話,可以這樣設定: | |||
<pre> | |||
from django.http import Http404, JsonResponse | |||
from . import config # import the config variables in the file './config.py'. | |||
def user(request, username): | |||
user_json = {"@context": "https://www.w3.org/ns/activitystreams", | |||
"id": config.site_url + "/users/" + username, | |||
"inbox": config.site_url + "/users/" + username + "/inbox", | |||
"outbox": config.site_url + "/users/" + username + "/outbox", | |||
"type": "Person", # the json for the type | |||
"name": username , # user name | |||
} | |||
if username != 'John': | |||
raise Http404() # throw 404 | |||
else: | |||
return JsonResponse(user_json) | |||
</pre> | |||
如果不是 John,就回傳 Http404()。 | |||
==參考== | |||
* https://docs.djangoproject.com | |||
* http://stackflow.com |