开发者

Django login, logout urls and current user name

开发者 https://www.devze.com 2022-12-25 17:40 出处:网络
I\'m new to Django and just just got django-registration up and running. Could anyone tell me how to get a get a log-in, log-out url name and the name of the current user in my template. Are these cal

I'm new to Django and just just got django-registration up and running. Could anyone tell me how to get a get a log-in, log-out url name and the name of the current user in my template. Are these called template tags? IS there a comprehensive list somewhere for all the default variables supplied with Django.

I开发者_StackOverflow社区'm a little lost with this. I've Googled for a while now but I couldn't find anything.

Thanks.


Make sure that you have 'django.contrib.auth.middleware.AuthenticationMiddleware' in settings.MIDDLEWARE_CLASSES

In template:

{{ request.user.username }}

The login and logout url can be found in settings:

  • settings.LOGIN_URL (default=/accounts/login)
  • settings.LOGOUT_URL (default=/accounts/logout)

You will have to implement those views and refer to it from url tag

{% url your.login.view.name %}

See..

  • http://docs.djangoproject.com/en/dev/topics/auth/
  • http://docs.djangoproject.com/en/dev/ref/settings
0

精彩评论

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