How to configure Django Dynamic Menu with the

My app is generating a list that would be the side menu, like this:

def generate_menu(request):
array = []
deviceList = []
    f1 = open('dictionary.txt', 'r')
    array =
    array = literal_eval(array)
    for i in sorted(array):
    context.update({'deviceList': deviceList})

return render(request, "device_list.html", context)

Now in my Template, I am doing this to create the menu based on dic file:


<nav id="sidebar">
    <ul class="list-unstyled components">
        <li class="active">
            <a href="device_list">Device List</a>
        {% block devices %}
        {% for each in deviceList %}
            <form action="/{{each}}" method="POST">
                {% csrf_token %}
                {{ form.as_p }}
                <button type="submit" value={{each}} name='DEVICES'>{{each}}</button>

        {% endfor %}
        {% endblock %}

url(r'^$', app.views.index),
url(r'^(?P<string>.+)$', app.views.generate_menu, name='DEVICES'),

and it doesn't work here. So how can I change the URL in a way to accept all kind of request like* because all device list names, are different and they need their own url. So I need to have a url path that is dynamic.

Back to Top