3 horizontal lines, burger
3 horizontal lines, burger

3 horizontal lines, burger
Remove all
LOADING ...

Django application for managing ad blocks from YAN

Clock
09.10.2025
/
Clock
09.10.2025
An eye
77
Hearts
0
Connected dots
0
Connected dots
0
Connected dots
0
Django app
Django app

Introduction

A comprehensive Django application for managing and displaying Yandex advertising blocks with advanced configuration options.
Already built-in features:
  1. Multiple Ad Types: Support for banners, full-screen ads, floor ads, top ads, carousels, and in-image ads
  2. Platform Targeting: Display ads on specific platforms (desktop, mobile, or cross-platform)
  3. Flexible Configuration: Manage ad locations, display frequency, and placement rules
  4. Middleware Integration: Automatic ad injection into templates based on view and template rules
  5. Customizable Templates: Extensible template system for different ad formats
  6. Context-Aware: Smart ad placement with context data integration
  7. Pagination Support: Automatic ad insertion between content pages

Models Overview

This app operates using four models: models for Ad Blocks (YandexAdBlock), models for the location of these ad blocks (YandexAdLocation), models for the blocks' configuration (YandexAdBlockConfiguration, which determines which units to use), and models for the current configuration (YandexCurrentAdBlockConfiguration, which determines which configuration to use on the website).
Let's look at each model separately.

YandexAdBlock

Defines individual ad blocks with properties:
  1. Ad Types:
  2. banner — adapts to the size of the surrounding container. The same block can be placed simultaneously on different versions of the website, and it will be shown on all devices.
  3. fullscreen — displays on the entire screen. A separate block must be created for each version of the website.
  4. floorAd — is fixed at the bottom of the screen over the website content. A separate block must be created for each version of the website.
  5. topAd — is fixed at the top of the screen over the website content on mobile devices only.
  6. feed — is displayed as a feed of ads. The same block can be placed simultaneously on different versions of the website, and it will be shown on all devices.
  7. inImage — is displayed over images on the website. The same block can be placed simultaneously on different versions of the website, and it will be shown on all devices.
  8. Push Triggers(A moment to load an Ad)
  9. on-load means as soon as possible
  10. on-intersection means when user's viewport intersects with an Ad element.
  11. Platform Targeting:
  12. Desktop — only on desktop devices
  13. Mobile — only on mobile devices
  14. Cross-platform — on both
Also, to connect the newly created record with the block made in YAN. You need to copy and paste the provided ID like this: R-A-17293858-16. 

YandexAdLocation

Maps an Ad'sad's blocks to specific locations on your site. You should specify them by yourself. For example, you decide to display your ad on the home page and insert this:
{% if isYandexAdManagerMiddlewareConnected %} {% for adlocation in adlocations %} {% if adlocation.adlocation_name == "HOME_FIRST_VISIBLE" %} {% include 'YandexAdManager/admanager_element.html' with adblock=adlocation.adblock%} {% endif %} {% endfor %} {% endif %}
When creating a new record in the database, you should name your location by HOME_FIRST_VISIBLE and choose the block to display.

YandexAdBlockConfiguration

Groups ad locations and defines display frequency for pagination pages, if there are some.

YandexCurrentAdBlockConfiguration

Singleton model to manage the currently active ad configuration.

Installation

This Django application is available on PyPI and can be downloaded using this command:
pip install django-yandex-ad-manager
After installing the application, you will need to connect it and configure it for correct operation. Add it to INSTALLED_APPS and MIDDLEWARE.
INSTALLED_APPS = [ # ... 'django_yandex_ad_manager.apps.YandexadmanagerConfig', # ... ] MIDDLEWARE = [ # ... 'django_yandex_ad_manager.middleware.AdManagerMiddleware', # ... ]
Since this is middleware, it is necessary to first indicate for which templates(and views) it is worthwhile to carry out work on determining advertising locations. You need to specify two arrays:
YANDEX_AD_MANAGER__ALLOWED_VIEWS = ('home', 'article', 'tool', 'tool_main') YANDEX_AD_MANAGER__ALLOWED_TEMPLATES = ('PagiScroll/base_post_list.html', 'Post/basic--post_preview-article.html', 'Post/basic--post_preview-note.html', 'Post/basic--post_preview-tool.html' )
Done. Everything is set up and configured. The last thing to do is to apply migrations and collect some static files.
python manage.py migrate python manage.py collectstatic
Now we've done for sure. The next thing left to do is to prepare your Django-templates to be used by YandexAdManager middleware.

Configuring templates

Firstly, we need to include header template. Include these in your base template's head section (<head> tag):
{% if isYandexAdManagerMiddlewareConnected %} {% include 'YandexAdManager/admanager_header.html' %} {% endif %}
Then, include scripts and styles:
{% block styles %} {% if isYandexAdManagerMiddlewareConnected %} {% include 'YandexAdManager/admanager_styles.html' %} {% endif %} {% endblock %} {% block scripts %} {% if isYandexAdManagerMiddlewareConnected %} {% include 'YandexAdManager/admanager_scripts.html' %} {% endif %} {% endblock %}
block scripts and block styles are a feature of my website, just be sure to include the necessary templates where they will be accessible to the middleware. That is, where you want to display ads.

Setting up ad locations

The last thing left to do is decide where we want to display the ad. To do this, select the location where you'd like to display the ad and insert the following code:
The blocks below should be used whenever you want your ad to be displayed. This is not applied to those Ad blocks without containers (topAd, floorAd, fullscreen, inImage)

Single Ad location

{% if isYandexAdManagerMiddlewareConnected %} {% for adlocation in adlocations %} {% if adlocation.adlocation_name == "AD_LOCATION_NAME" %} {% include 'YandexAdManager/admanager_element.html' with adblock=adlocation.adblock%} {% endif %} {% endfor %} {% endif %}
When you create another entry in the database through the admin panel, insert into the field with the location name — AD_LOCATION_NAME.

Multiple Ad locations

If a single page contains multiple ad locations using the same ad unit, you'll need to use the unificator variable to ensure proper operation with Yandex's API and avoid confusion.
{% if isYandexAdManagerMiddlewareConnected %} {% for adlocation in adlocations %} {% if adlocation.adlocation_name == "AD_LOCATION_ONE" %} {% include 'YandexAdManager/admanager_element.html' with adblock=adlocation.adblock unificator="home_first_visible" %} {% endif %} {% if adlocation.adlocation_name == "AD_LOCATION_TWO" %} {% include 'YandexAdManager/admanager_element.html' with adblock=adlocation.adblock unificator="home_second_visible" %} {% endif %} {% endfor %} {% endif %}
Or like this:
{% if isYandexAdManagerMiddlewareConnected %} {% for adlocation in adlocations %} {% if adlocation.adlocation_name == "AD_LOCATION_ONE" %} {% include 'YandexAdManager/admanager_element.html' with adblock=adlocation.adblock unificator="home_first_visible" %} {% endif %} {% endfor %} {% endif %} {% if isYandexAdManagerMiddlewareConnected %} {% for adlocation in adlocations %} {% if adlocation.adlocation_name == "AD_LOCATION_TWO" %} {% include 'YandexAdManager/admanager_element.html' with adblock=adlocation.adblock unificator="home_first_visible" %} {% endif %} {% endfor %} {% endif %}

Ad location in pagination

If you want ads to appear on pagination pages between articles, for example, you should use this template:
{% if isYandexAdManagerMiddlewareConnected %} {# Ads between articles in pagination #} {% for adlocation in adlocations %} {% if adlocation.adlocation_name == "ON_PAGISCROLL_ARTICLES_BETWEEN_PAGES" %} {% include 'YandexAdManager/admanager_element_in_pagination.html' with page=page adblock=adlocation.adblock %} {% endif %} {% endfor %} {% endif %}

Best Practices

  1. Use descriptive unificators to track ad performance in different locations
  2. Test on multiple devices when using platform targeting
  3. Monitor ad density to avoid overwhelming users
  4. Use intersection-based loading for better performance
  5. Configure appropriate ad types for different content contexts

Troubleshooting

Ads Not Showing

  1. Check if middleware is properly configured
  2. Verify isYandexAdManagerMiddlewareConnected is True in templates
  3. Ensure ad locations are properly configured in admin
  4. Check browser console for JavaScript errors


Note: This package is not officially affiliated with Yandex. It's a community-maintained Django integration for Yandex Advertising Network.

Similar tools

Clock
25.04.2025
/
Clock
21.05.2025
/
Django app
Scraper
An eye
357
Hearts
0
Connected dots
0
Connected dots
0
Connected dots
0
This tool is a Django application that generates the "Table of contents" of the page on which it is installed. Due to the peculiarity of the Django framework, all generation occurs on the server, that is, the SSR rendering method. This application also creates anchor links to the collected chapters, if the heading have an id attribute.
Clock
27.04.2025
/
Clock
21.05.2025
/
Django app
An eye
386
Hearts
1
Connected dots
0
Connected dots
0
Connected dots
0
This tool is a Django application that generates "Breadcrumbs" of the page it is installed on. Due to the peculiarity of the Django framework, all generation occurs on the server, i.e. SSR rendering method.

Do not forget to share, like and leave a comment :)

Reviews

(0)

captcha
Send
LOADING ...
It's empty now. Be the first (o゚v゚)ノ