Django with paypal sandbox

Hello! I have books model with url and I want to hide url before someone will purchase for it, my models.py:

class Book(models.Model):
    name = models.TextField()
    description = models.TextField()
    book = models.FileField(upload_to='books/')

class BookImage(models.Model):
    book = models.ForeignKey(Book, on_delete=models.CASCADE)
    name = models.ImageField(upload_to='images/')

html template:

{% extends "base.html" %}

{% block content %}
<ol>
    {% for book in books %}
    <li class="post">
        <div>
            <b>Name: {{ book.name }}</b>
        </div>
        <div>
            <b>Description: {{ book.description }}</b>
        </div>
        <div>
            <a href="{{ book.book.url }}" target="_blank" rel="noopener noreferrer">{{ book.book }}</a> // I want to hide this url before purchase
        </div>
        <hr>
        {% for image in book.bookimage_set.all %}
        <div id="carouselExample" class="carousel slide">
            <div class="carousel-inner">
                {% for image in book.bookimage_set.all %}
                <div class="carousel-item {% if forloop.first %}active{% endif %}">
                    <img src="{{ image.name.url }}" class="d-block w-100" alt="{{ image.name }}">
                </div>
                {% endfor %}
            </div>
            <button class="carousel-control-prev" type="button" data-bs-target="#carouselExample" data-bs-slide="prev">
                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                <span class="visually-hidden">Previous</span>
            </button>
            <button class="carousel-control-next" type="button" data-bs-target="#carouselExample" data-bs-slide="next">
                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                <span class="visually-hidden">Next</span>
            </button>
        </div>
        {% endfor %}
    </li>
    <hr>
    {% endfor %}
</ol>
{% endblock %}

I’m not seeing any logic here for payment. If you want to hide an element, you’ll need to make sure the relevant context is available to the template, and wrap the required content in an {% if %}.

Just I want to learn working with layment systems to make e-commerce websites, e.g. pdf books store.

I’m not sure what you mean by this? By the sounds of it you’re just trying to hide an element. Your exact use case doesn’t change the code needed to do it.