ビューに特定のベース リファラーがある場合、簡単な通知を設定したいと思います。
http://myapp.com/page/
に着陸し、 から来たとしましょうhttp://myapp.com/other/page/1
。これは私の疑似コードの例です。基本的に、任意のページ/XI から来て、通知をセットアップしたい場合です。
のようなものかもしれないと思っていますが^r^myapp.com/other/page/$
、Pythonで正規表現を使用する方法にあまり慣れていません。
from django.http import HttpRequest
def someview(request):
notify = False
... # other stuff not important to question
req = HttpRequest()
test = req.META['HTTP_REFERER'] like "http://myapp.com/other/page*"
# where * denotes matching anything past that point and the test returns T/F
if test:
notify = True
return # doesn't matter here
これは、特にdjangoの質問ではなく、「このコンテキストで正規表現を使用するにはどうすればよいですか」のようなものかもしれません。