from classytags.helpers import InclusionTag
from django import template
from django.template.loader import render_to_string


register = template.Library()


class CookielawBanner(InclusionTag):
    """
    Displays cookie law banner only if user has not dismissed it yet.
    """

    template = 'cookielaw/banner.html'

    def render_tag(self, context, **kwargs):
        template = self.get_template(context, **kwargs)
        if context['request'].COOKIES.get('cookielaw_accepted', False):
            return ''
        data = self.get_context(context, **kwargs)
        return render_to_string(template, data)

register.tag(CookielawBanner)


from django import template
from django.template.loader import render_to_string


register = template.Library()


@register.simple_tag(takes_context=True)
def cookielaw_banner(context):
    if context['request'].COOKIES.get('cookielaw_accepted', False):
        return ''
    return render_to_string('cookielaw/banner.html', context)


Use Django simple_tag instead of classytags because there were no context in template rendering.
Use Django simple_tag instead of classytags because there were no context in template rendering.
- from classytags.helpers import InclusionTag
+ 
  from django import template
  from django.template.loader import render_to_string
  
  
  register = template.Library()
  
  
- class CookielawBanner(InclusionTag):
-     """
-     Displays cookie law banner only if user has not dismissed it yet.
-     """
+ @register.simple_tag(takes_context=True)
+ def cookielaw_banner(context):
+     if context['request'].COOKIES.get('cookielaw_accepted', False):
+         return ''
+     return render_to_string('cookielaw/banner.html', context)
  
-     template = 'cookielaw/banner.html'
  
-     def render_tag(self, context, **kwargs):
-         template = self.get_template(context, **kwargs)
-         if context['request'].COOKIES.get('cookielaw_accepted', False):
-             return ''
-         data = self.get_context(context, **kwargs)
-         return render_to_string(template, data)
- 
- register.tag(CookielawBanner)
- 
Use Django simple_tag instead of classytags because there were no context in template rendering.
## Code Before:
from classytags.helpers import InclusionTag
from django import template
from django.template.loader import render_to_string


register = template.Library()


class CookielawBanner(InclusionTag):
    """
    Displays cookie law banner only if user has not dismissed it yet.
    """

    template = 'cookielaw/banner.html'

    def render_tag(self, context, **kwargs):
        template = self.get_template(context, **kwargs)
        if context['request'].COOKIES.get('cookielaw_accepted', False):
            return ''
        data = self.get_context(context, **kwargs)
        return render_to_string(template, data)

register.tag(CookielawBanner)

## Instruction:
Use Django simple_tag instead of classytags because there were no context in template rendering.
## Code After:

from django import template
from django.template.loader import render_to_string


register = template.Library()


@register.simple_tag(takes_context=True)
def cookielaw_banner(context):
    if context['request'].COOKIES.get('cookielaw_accepted', False):
        return ''
    return render_to_string('cookielaw/banner.html', context)

