1

i tried to insert it via dtl variables but there were html tags on the page

models.py

html code in desciption field

class Vacancy(models.Model):
    title = models.CharField(max_length=100)
    specialty = models.ForeignKey(Specialty, on_delete=models.CASCADE, related_name="vacancies")
    company = models.ForeignKey(Company, on_delete=models.CASCADE, related_name="vacancies")
    skills = models.TextField()
    description = models.TextField()
    salary_min = models.FloatField()
    salary_max = models.FloatField()
    published_at = models.DateTimeField()

html

 <a href="#"><img src="/media/company_images/{{ vacancy.company.logo }}" width="130" height="80" alt=""></a>
          <div class="d-flex align-items-baseline align-content-baseline">
            <h1 class="h2 mt-4 font-weight-bold" >{{ vacancy.title }}</h1>
            <p class="m-0 pl-3">{{ vacancy.salary_min }}р – {{ vacancy.salary_max }}р</p>
          </div>
          <p class="mt-2">{{ vacancy.skills }}</p>
          <p class="text-muted mb-4">Primal Assault (15-30 человек), Рязань или удаленно</p>
          <div style="line-height: 1.8;">
            {{ vacancy.description }}
          </div>
4
  • Can you describe more? What you actually want? Commented Jun 19, 2021 at 15:26
  • i have some html code in my database, i need to insert it to my html template, but if i insert it via dtl variables my inserted code displays incorrectly Commented Jun 19, 2021 at 15:40
  • What do you mean by html code in database? Do you mean you want to import a full html file from database? Commented Jun 19, 2021 at 15:59
  • nope , i have html code , not html file Commented Jun 19, 2021 at 16:01

1 Answer 1

6

If you want to render HTML from your database you can use the safe filter in your jinja HTML.

{{ YOUR_HTML_CONTENT_FROM_DATABASE | safe }}

You can also use the autoescape as defined here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.