"第一次来这里?" 与Django的消息

pan*_*ore 2 django

我正在编写一个应用程序,它将根据首次访问者显示注册视图.

什么以及如何使用Django更好的方法?

thxs.

rz.*_*rz. 6

使用会话:https://docs.djangoproject.com/en/1.8/topics/http/sessions/

然后做一些像:

def my_view(request, *args, **kwargs):
    if request.session.get('visited', False):
        # response without the welcome message
    else:
        request.session['visited'] = True
        # response with the welcome message
Run Code Online (Sandbox Code Playgroud)

对于与会话相关的设置(例如到期),请参阅https://docs.djangoproject.com/en/1.8/topics/http/sessions/#browser-length-sessions-vs-persistent-sessions