N
N
Northxstar2019-04-07 18:23:10
PostgreSQL
Northxstar, 2019-04-07 18:23:10

How to display data from a table decoded via base64?

In a Postgres table, one of the fields stores data in base64. They need to be output by running through decode(), and the rest - as is.
models.py:

class Local(models.Model):

    packet = models.TextField(blank=True) #он в base64
    protocol = models.TextField(blank=True)
    srcaddr = models.TextField(blank=True)
    srcport = models.TextField(blank=True)
    dstaddr = models.TextField(blank=True)
    dstport = models.TextField(blank=True)
    ttl = models.TextField(blank=True)
    capturetime = models.TextField(blank=True)

views.py:
def local(request):
    table = Local.objects.order_by('-id')
    return render(request, "local.html",{"packets": table}) #сейчас передача всего как есть

On html:
<tbody>
                    
                  
                     {% for p in packets %}
                        <tr>
                          <td>
                          <details>
                          <summary>{{ p.capturetimel}}{{ p.protocol}}{{ p.srcaddr}}{{ p.srcport}} {{ p.dstaddr}} {{ p.dstport}} {{ p.ttl}}</summary>
                          <pre>

                                    {{ p.packet }}
                          </pre>
                          
                          </td>
                        </tr>
                    {% endfor %}
                                
                               
    
                                </tbody>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pijng, 2019-04-08
@Pijng

jinja has a built-in filter. b64decode
Accordingly, you can display your parameter like this:
List of all filters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question