Jump to content

Include em django


dudusf04

Recommended Posts

Olá M6, 

Desde já obrigado pela explicação.  Já estive a estudar na documentação e também vendo uns vídeos no youtube.

A questão é a seguinte, eu criei um dicionário na views.py que faz uma listagem de ficheiros criei a rota para file_backup.html, até ai tudo bem, quando no device faço o include só aparece o que está em HTML, o que está em python não.

 

views.py

def File_b(request):
    path = '/opt/netbox/netbox/static/backup'
    allfiles = []

    # r=root, d=directories, f = files
    for r, d, f in os.walk(path):
        for fil in f:
            if '.txt' in fil:
               allfiles.append(os.path.join('backup/', fil))
            if '.xml' in fil:
               allfiles.append(os.path.join('backup/', fil))
    return render(request, 'dcim/file_backup.html', { 'files':allfiles,})

urls.py

 # file backups
    path(r'file_backup/', views.File_b, name='files'),

file_backup.html

 {% load static %}
    <table class="table table-hover panel-body">
        <tr>
            <th>Name</th>
            <th>Size</th>
            <th>Created</th>
            <th></th>
        </tr>
            {% for fil in files %}
                <tr{% if not file.size %} class="danger"{% endif %}>
                   <td>
                       <i class="fa fa-image"></i>
                       <a href="{% static fil %}" target="_blank">{{ fil }}</a>
                   </td>
                   <td>{{ fil.size|filesizeformat }}</td>
                   <td>{{ fil.created }}</td>
                </tr>
           {% endfor %}
    </table>

device.html

<div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Backup</strong>
                </div>
                {% include 'dcim/file_backup.html' %}
                {% if perms.extras.add_imageattachment %}
                    <div class="panel-footer text-right noprint">
                        <a href="https://ipam.winprovit.pt/dcim/file_backup/" target="_blank" class="btn btn-xs
btn-primary">
                            <span class="glyphicon" aria-hidden="true"></span>
                                backups
                        </a>
                    </div>
                {% endif %}   
            </div>
Edited by dudusf04
Link to comment
Share on other sites

Não estou a conseguir compreender o teu problema.
Tens um bug no código?
Não consegues passar a informação do controlador para a view?
Tens outro problema?

10 REM Generation 48K!
20 INPUT "URL:", A$
30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50
40 PRINT "404 Not Found"
50 PRINT "./M6 @ Portugal a Programar."

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.