How can I get the page title in the template? I know there are ways to do this with javascript, but I’ll prefer a template-tag or a variable if it exists.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The page title is an html element (
<title>Title Here</title>), anddjangohas no idea what that is.Django’s templates render the raw HTML text, which a browser parses and only then does the concept of a page title exist for javascript to parse.
If you need it in django, you’d want to ensure django is building that title tag and you would access it in the same way you’d display any other variable in a template.
It’s probably best left to the DOM tools since a title might be created in any number of ways. If you absolutely need it in django, I would probably parse the final rendered HTML with an HTML parser like BeautifulSoup.