Sometimes I need previous page for some reasons.
- Redirect to previous page after delete object in detail page
- Redirect to previous page when login/loggout …
You can know previous page with request
.
Django request has many information with META
tag. It has many useful data such as browser information, site domain, and so on.
In here, you can check example of request.META
headers.
This META
also has previous page information - HTTP_REFERER
. If exist, it has it’s referring page.
So you can use like this
In views
prev_page = request.META.get('HTTP_REFERER')
In templates
{{ request.META.HTTP_REFERER }}
'backend > django' 카테고리의 다른 글
Django: multiple pagination in CBV (0) | 2018.03.30 |
---|---|
django: 기본 비밀번호 validation 수정하기 (0) | 2018.03.22 |
django admin을 잘 쓰자! - 장고 어드민 cookbook (0) | 2018.03.13 |
django test plus (0) | 2018.02.27 |
django model test - model_mommy (0) | 2018.02.26 |