简体   繁体   中英

How to get text inside <a> tag in views.py django via form action?

I have a list in my function in views.py and displayed them in the html page as tags. When i click on any of the tag i need to get those text of tags in another function in views.py when the form is submitted.Please help.

def index(request):

     vendor_data = requests.get('https://cve.circl.lu/api/browse').content
     vendors = json.loads(vendor_data)
     vendor_list = []
     context = {}

     for i in range(len(vendors['vendor'])):
         vendor_list.append(vendors['vendor'][i])
    
     paginator = Paginator(vendor_list, 50)
     page_number = request.GET.get('page')

    
     context['page_obj'] = paginator.get_page(page_number)
     return render(request,'index.html',context)

index.html

 <form action="{% url 'appVuldb:output' %}" method="POST" id="venform">
                    {% csrf_token %}
                    
                    {%for vendor in page_obj%}
                        <ul>
                            <li>
                                
                                <a href="javascript:void(0);" class="link" name="vendor_name" 
                                
                                onclick="document.forms['venform'].submit();">{{vendor}}
                                </a>
                            </li>
                        </ul>        

                    {%endfor%}
                </form>`

使用隐藏输入:

<input type="hidden" value="{{ vendor }}" name="vendor_name"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM