开发者

"first time here?" message with django

开发者 https://www.devze.com 2023-01-02 14:47 出处:网络
Im writing an app that will display the register view depending if is first time visitor. What and How is 开发者_C百科the better way to do this with Django?

Im writing an app that will display the register view depending if is first time visitor.

What and How is 开发者_C百科the better way to do this with Django?

thxs.


Use sessions: https://docs.djangoproject.com/en/1.8/topics/http/sessions/

And then do something like:

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

For session-related settings (e.g. expiration), see https://docs.djangoproject.com/en/1.8/topics/http/sessions/#browser-length-sessions-vs-persistent-sessions

0

精彩评论

暂无评论...
验证码 换一张
取 消