Home > Net >  meta tags shows in <body> While Should be placed in the <head>
meta tags shows in <body> While Should be placed in the <head>

Time:09-22

I have a website based on the django framework. I want to add meta tags to the website With conditions :

"""Definition of models."""

from django.db import models

class Pages_Meta(models.Model):
      Page_name = models.TextField(null=False)
      Page_meta  = models.TextField(null=False)
      page_title = models.TextField(null=False)

And html page is:

<html>
   <head>
       <title> {{ title }} - Farhad Dorod  </title>
       {{ meta }}
   </head>
</html>
<body>  ...  </body>

And urls.py is:

path('index/',
     LoginView.as_view(
         template_name='app/index.html',
         extra_context=
         {
             'title': Pages_Meta.objects.get(id = 1).page_title,
             'meta' : Pages_Meta.objects.get(id = 1).Page_meta,
         }),
     name='index')

result: all meta tags shows in body While Should be placed in the head

enter image description here

CodePudding user response:

Using Django's template tag safe you can approve the content as html safe, allowing it to render as html. Like so:

{{ meta|safe }}
  • Related